洛谷 P8741 [蓝桥杯 2021 省 B] 填空问题 题解

题目分析

A 空间

简单的单位换算题:
1 MB = 1024 KB = 1048576 B = 8388608 b 256 × 8388608 ÷ 32 = 67108864 1\text{MB}=1024\text{KB}=1048576\text{B}=8388608\text b\\ 256\times8388608\div32=67108864 1MB=1024KB=1048576B=8388608b256×8388608÷32=67108864

故答案为 67108864 67108864 67108864。

B 卡片

用一个数组存储每种卡片剩余的数量,再从 1 1 1 开始,一个个判断每个数需要的卡片是否够用,如果不够用了就输出结果。最终可以得到答案为 3181 3181 3181。

C 直线

枚举每一种组合然后去掉重复的部分即可。

对于去重,可以使用 set 来实现。

代码如下:

cpp 复制代码
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
signed main() {
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	vector<pair<int,int>>vec;
	set<pair<pair<int,int>,int>>ans;
	for(int i=1;i<=20;++i) for(int j=1;j<=21;++j) vec.push_back({i,j});//枚举组合
	for(int i=0;i<vec.size()-1;++i)
		for(int j=i+1;j<vec.size();++j) {
			int x1=vec[i].first,y1=vec[i].second,x2=vec[j].first,y2=vec[j].second;
			int a=x2-x1,b=y1-y2,c=x1*y1-x2*y2;
			int gcd=__gcd(__gcd(a,b),c);
			ans.insert({{b/gcd,a/gcd},c/gcd});//去重
		}
	cout<<ans.size();//输出答案
	return 0;
}

得到答案为 40257 40257 40257。

D 货物摆放

计算出 n n n 的所有因数储存起来,再枚举所有的组合,如果乘积刚好等于 n n n,就累加答案。最终可以得到答案为 2430 2430 2430。

E 路径

就是一个求最短路径的板子题,可以使用 Dijkstra 算法。最终得到答案是 10266837 10266837 10266837。

Code

cpp 复制代码
#include<iostream>
using namespace std;
signed main() {
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	string ans[]={
		"67108864",
		"3181",
		"40257",
		"2430",
		"10266837"
	};
	cout<<ans[getchar()-'A'];
	return 0;
}
相关推荐
clint4562 天前
C++进阶(1)——前景提要
c++
夜悊3 天前
C++代码示例:进制数简单生成工具
c++
郝学胜_神的一滴3 天前
CMake 021: IF 条件判据详诠
c++·cmake
_wyt0013 天前
洛谷 B3930 [GESP202312 五级] 烹饪问题 题解
c++·gesp
玖玥拾3 天前
C/C++ 数据结构(七)栈、容器适配器
c语言·数据结构·c++··容器适配器
один but you3 天前
constexpr函数
c++
凡人叶枫3 天前
Effective C++ 条款41:了解隐式接口和编译期多态
java·开发语言·c++·effective c++
凡人叶枫3 天前
Effective C++ 条款42:了解 typename 的双重意义
java·linux·服务器·c++
小胖xiaopangss3 天前
BRpc使用
c++·rpc
-森屿安年-3 天前
63. 不同路径 II
c++·算法·动态规划