// 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;}
#include<iostream>#include<cstring>usingnamespace std;typedeflonglong ll;intmain(){ll fenmu =4*3*2;ll fenzi =1;for(int i =2020; i >=2017;-- i)fenzi *= i;cout << fenzi / fenmu;}
試題 E: 城邦
prim
// 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});}}}