// 59375#include<iostream>usingnamespace std;constint mod =100000;intmain(){int n =2021;int res =1;for(int i =1; i <=2021; i +=2){
res =(res * i)% mod;}
cout << res;}
// 4046#include<iostream>#include<cstring>usingnamespace std;typedeflonglong ll;int dist[2030];int g[2030][2030];bool st[2030];intcalc(int x,int y){int a[5], b[5];for(int i =0; i <4;++ i){
a[i]= x %10;
b[i]= y %10;
x /=10, y /=10;}int res =0;for(int i =0; i <4;++ i){if(a[i]!= b[i])
res += a[i]+ b[i];}return res;}intprim(){memset(dist,0x3f,sizeof dist);int res =0;
dist[1]=0;for(int i =0; i <2021;++ i){int t =-1;for(int j =1; j <=2021;++ j){if(!st[j]&&(t ==-1|| dist[j]< dist[t])){
t = j;}}
st[t]=true;
res += dist[t];for(int j =1; j <=2021;++ j)
dist[j]=min(dist[j], g[t][j]);}return res;}intmain(){for(int i =1; i <=2021;++ i){for(int j =1; j <=2021;++ j){if(i == j) g[i][j]= g[j][i]=0x3f3f3f3f;
g[i][j]= g[j][i]=calc(i, j);}}
cout <<prim();}
kruscal
#include<iostream>#include<algorithm>usingnamespace std;constint N =2021*2021+10, M =2021+10;structEdge{int a, b, w;booloperator<(Edge const&e)const{return w < e.w;}}e[N];int cnt =0;int p[M];intcalc(int x,int y){int a[5], b[5];for(int i =0; i <4;++ i){
a[i]= x %10;
b[i]= y %10;
x /=10, y /=10;}int res =0;for(int i =0; i <4;++ i){if(a[i]!= b[i])
res += a[i]+ b[i];}return res;}intfind(int x){if(p[x]!= x) p[x]=find(p[x]);return p[x];}intkruscal(){int res =0;for(int i =1; i <=2021;++ i)
p[i]= i;for(int i =0; i < cnt;++ i){int a = e[i].a, b = e[i].b, w = e[i].w;
a =find(a);
b =find(b);if(a == b)continue;
res += w;
p[a]= b;}return res;}intmain(){for(int i =1; i <=2021;++ i){for(int j =1; j <=2021;++ j){
e[cnt ++]={i, j,calc(i, j)};}}sort(e, e + cnt);
cout <<kruscal();}
试题 F: 特殊年份
#include<iostream>usingnamespace std;boolcheck(int x){int a[5];for(int i =0; i <4;++ i){
a[i]= x %10;
x /=10;}if(a[1]== a[3]&& a[0]-1== a[2])returntrue;returnfalse;}intmain(){int cnt =0;for(int i =0; i <5;++ i){int year;
cin >> year;if(check(year))
cnt ++;}
cout << cnt;}
试题 G: 小平方
#include<iostream>usingnamespace std;intmain(){int n;
cin >> n;int cnt =0;for(int i =1; i <= n -1;++ i){int pf = i * i;if(pf % n < n /2.0)
cnt ++;}
cout << cnt;}
试题 H: 完全平方数
#include<iostream>#include<cmath>usingnamespace std;boolcheck(int x){int t =(int)sqrt(x);if(t * t == x)returntrue;returnfalse;}intmain(){int n;
cin >> n;for(int i =1; i <= n;++ i){if(check(i * n)){
cout << i << endl;return0;}}}
试题 I: 负载均衡
#include<iostream>#include<queue>usingnamespace std;typedef pair<int,int> PII;constint N =2e5+10;int power[N];
priority_queue<PII, vector<PII>, greater<PII>> que[N];// 小顶堆数组intmain(){int n, m;
cin >> n >> m;for(int i =1; i <= n;++ i)
cin >> power[i];while(m --){int a, b, c, d;
cin >> a >> b >> c >> d;while(que[b].size()&& que[b].top().first <= a){
power[b]+= que[b].top().second;
que[b].pop();}if(power[b]< d){
cout <<-1<< endl;}else{
power[b]-= d;
cout << power[b]<< endl;
que[b].push({a + c, d});}}}
试题 J: 国际象棋
典型的 状压dp
由于这里行数比列数少,因此我们枚举每一列的摆放状态
f
[
i
]
[
a
]
[
b
]
[
j
]
f[i][a][b][j]
f[i][a][b][j]表示考虑前i列,第i-1列状态为a,第i列状态为b,且一共放了j个马(因为这道题与数量有关)的方案数
确定正确的初始状态
#include<iostream>usingnamespace std;constint N =110, M =(1<<6), K =21, MOD =1e9+7;int f[N][M][M][K];intget_count(int x){// 二进制下1的个数int res =0;while(x){
res ++;
x -=(x &-x);}return res;}intmain(){int n, m, k;
cin >> n >> m >> k;
f[0][0][0][0]=1;// 初始状态for(int i =1; i <= m;++ i){// 枚举每一列for(int a =0; a <(1<< n);++ a){// 第i-2列for(int b =0; b <(1<< n);++ b){// 第i-1列if((a &(b <<2))||((a <<2)& b))continue;// 状态矛盾for(int c =0; c <(1<< n);++ c){// 第i列if((c &(b <<2))||((c <<2)& b))continue;// 状态矛盾if((c &(a <<1))||((c <<1)& a))continue;// 状态矛盾int t =get_count(c);// 根据第i列个数来确定总个数的下限for(int j = t; j <= k;++ j){// 枚举总个数
f[i][b][c][j]=(f[i][b][c][j]+ f[i -1][a][b][j - t])% MOD;}}}}}int res =0;for(int i =0; i <(1<< n);++ i){for(int j =0; j <(1<< n);++ j){
res =(res + f[m][i][j][k])% MOD;}}
cout << res;}
试题A :取余1试题 B: 双阶乘// 59375#include <iostream>using namespace std;const int mod = 100000;int main() { int n = 2021; int res = 1; for (int i = 1; i <= 2021; i += 2) { res = (res * i) % mod; } cout << res;