P8751 [蓝桥杯 2021 省 B2] 填空问题
问题 A
思路:很简单,只要用 % 取余就可以了。
code:
#include <bits/stdc++.h>
using namespace std;
int main(){
cout << 2021 % 20;
return 0;
}
答案为
问题 B
思路:
按照题目所给的公式,进行计算,由于题目说输出后五位,
所以我们每次乘完取余都需要
code:
#include <bits/stdc++.h>
using namespace std;
int main(){
int ans = 1;
for(int i = 2021; i >= 1; i -= 2){
ans *= i;
ans %= 100000;
}
cout << ans;
return 0;
}
答案是
问题 C
思路:
直接暴力枚举出所有可能,枚举成边长
code
#include <bits/stdc++.h>
using namespace std;
int main(){
int ans = 0;
for(int i = 1; i <= 2021; i++){
for(int j = 1; j <= 2021; j++){
if(i * j <= 2021){
ans++;
}
}
}
cout << ans;
}
答案是
问题 D
思路:
五重暴力枚举,时间复杂度飘上天,但是这是提交答案题,不用管它,算出来填上去就行了!!!
(然后我就为此废了
code:
#include <bits/stdc++.h>
using namespace std;
int main(){
long long ans = 0;//不开longlong见祖宗
for(int a = 1; a <= 2021; a++){
for(int b = 1; b <= 2021; b++){
for(int c = 1; c <= 2021; c++){
for(int d = 1; d <= 2021; d++){
for(int e = 1; e <= 2021; e++){
if(a+b+c+d+e==2021){//暴力枚举
ans++;
}
}
}
}
}
}
cout << ans;
}
时间复杂度实在太高,必须得想一些优化的办法,这时就有一种新的方法:
将
code:
#include <bits/stdc++.h>
using namespace std;
int main(){
long long ans = 1;
for(int i = 2020; i >= 2017; i--){
ans *= i;
}
cout << ans / (4 * 3 * 2 * 1);
}
得到得数
问题 E
思路就是使用最小生成树和并查集,找到答案。
由于代码长度问题,就不贴了。
答案是