#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>usingnamespace std;typedeflonglong LL;constint N =500;
LL a[N];int sz;boolCheck(LL n){for(int i =0; i <= sz; i ++){if(n == a[i])returnfalse;}returntrue;}intmain(){int T; cin >> T;LL n;a[0]=1;sz =60;for(int i =1; i <= sz; i ++)a[i]= a[i -1]*2;while(T --){scanf("%lld",&n);if(Check(n)){cout <<"YES"<< endl;}else{cout <<"NO"<< endl;}}return0;}
B
#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>usingnamespace std;typedeflonglong LL;constint N =1000010;bool st[N +10];intmain(){int T; cin >> T;memset(st,false,sizeof st);st[2020]= st[2021]=true;for(int i =2022; i < N; i ++){st[i]= st[i -2020]| st[i -2021];}while(T --){staticint x;scanf("%d",&x);if(st[x]) cout <<"YES\n";else cout <<"NO\n";}return0;}
C
#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>usingnamespace std;typedeflonglong LL;constint N =200010;int cnt1[N], cnt2[N];int n, m, k;intmain(){int T; cin >> T;while(T --){scanf("%d%d%d",&n,&m,&k);staticint x;static LL res;res =0LL;memset(cnt1,0,sizeof cnt1);memset(cnt2,0,sizeof cnt2);for(int i =1; i <= k; i ++){scanf("%d",&x);cnt1[x]++;}for(int i =1; i <= k; i ++){scanf("%d",&x);cnt2[x]++;}res =LL(k)*(k -1);for(int i =1; i <= n; i ++){res -=LL(cnt1[i])*(cnt1[i]-1);}for(int i =1; i <= m; i ++){res -=LL(cnt2[i])*(cnt2[i]-1);}cout << res /2<< endl;}return0;}
D
#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>usingnamespace std;typedeflonglong LL;constint N =200010, INF =0x3f3f3f3f;int n, m;int a[N];
LL c[N], d[N];int szc, szd;boolcmp(LL a, LL b){return a > b;}intmain(){int T; cin >> T;while(T --){staticint b;cin >> n >> m;for(int i =1; i <= n; i ++)scanf("%d",&a[i]);c[0]= d[0]= szc = szd =0;for(int i =1; i <= n; i ++){scanf("%d",&b);if(b &1)c[++ szc]= a[i];elsed[++ szd]= a[i];}sort(c +1, c + szc +1, cmp);sort(d +1, d + szd +1, cmp);for(int i =1; i <= szc; i ++) c[i]+= c[i -1];for(int i =1; i <= szd; i ++) d[i]+= d[i -1];if(c[szc]+ d[szd]< m){puts("-1");}else{int res = INF;for(int i =0; i <= szc; i ++){if(c[i]+ d[szd]< m)continue;elseif(c[i]>= m){res =min(res, i);break;}else{staticint tmp;tmp =lower_bound(d +1, d +1+ szd, m - c[i])- d;res =min(res, tmp + tmp + i);}}cout << res << endl;}}return0;}
E
#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>usingnamespace std;typedeflonglong LL;constint N =1010, INF =0x3f3f3f3f;constint MOD =1e9+7;int n, k;int a[N];int f[N][N];boolcmp(LL a, LL b){return a > b;}intmain(){memset(f,0,sizeof f);for(int i =0; i < N; i ++)f[i][i]= f[i][0]=1;for(int i =1; i < N; i ++)for(int j =1; j <= i; j ++)f[i][j]=(f[i -1][j]+ f[i -1][j -1])% MOD;int T; cin >> T;while(T --){cin >> n >> k;for(int i =1; i <= n; i ++)scanf("%d",&a[i]);sort(a +1, a + n +1, cmp);staticint x, sidx, eidx;x = a[k], sidx =-1, eidx =-1;for(int i =1; i <= n; i ++){if(a[i]== x){if(sidx ==-1) sidx = i;eidx = i;}}cout << f[eidx - sidx +1][k - sidx +1]<< endl;}return0;}
F
#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>usingnamespace std;typedeflonglong LL;constint N =1010, INF =0x3f3f3f3f;constint MOD =1e9+7;int n;char a[N][N], b[N][N];char c[N][N];inlinevoidChange(char c[][N],int x,bool row);boolSame(char c[][N],char d[][N],int x){for(int i =1; i <= n; i ++)if(c[x][i]!= d[x][i])returnfalse;returntrue;}boolCheck(char c[][N],char d[][N]){// 第一行是不需要动的,我们看看 列 的影响for(int i =1; i <= n; i ++)if(c[1][i]!= d[1][i])Change(c, i,false);for(int i =2; i <= n; i ++){if(c[i][1]!= d[i][1])// 修改 行Change(c, i,true);if(!Same(c, d, i))returnfalse;}returntrue;}inlinevoidChange(char c[][N],int x,bool row){if(row)// rowfor(int i =1; i <= n; i ++){c[x][i]=97- c[x][i];// 48 + 49 - c[i]}else// colfor(int i =1; i <= n; i ++){c[i][x]=97- c[i][x];// 48 + 49 - c[i]}}intmain(){int T; cin >> T;while(T --){cin >> n;for(int i =1; i <= n; i ++)scanf("%s", a[i]+1);for(int i =1; i <= n; i ++)scanf("%s", b[i]+1);memcpy(c, a,sizeof c);if(Check(c, b)||(memcpy(c, a,sizeof c),Change(c,1,true),Check(c, b)))puts("YES");elseputs("NO");}return0;}
G
#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>usingnamespace std;typedeflonglong LL;constint N =200010, INF =0x3f3f3f3f;int cnt[N];int a[N];bool st[N];int f[N];int n;intmain(){int T; cin >> T;while(T --){staticint res;cin >> n;for(int i =1; i <= n; i ++)scanf("%d",&a[i]);res = INF;sort(a +1, a +1+ n);memset(cnt,0,sizeof cnt);memset(st,false,sizeof st);memset(f,0,sizeof f);for(int i =1; i <= n; i ++) cnt[a[i]]++;for(int i =1, val; i <= n; i ++){val = a[i];if(st[val])continue;st[val]=true;// cnt[val] = max(cnt[val], 1);f[val]= f[val]+ cnt[val];// 给自己加的for(int j = val + val; j < N; j += val){f[j]=max(f[j], f[val]);// 给别的数字加的}res =min(res, n - f[val]);}cout << res << endl;}return0;}
Codeforces Round #698 (Div. 2) A-E解题报告与解法证明
题目解法总体概括 A Nezzar and Colorful Balls #include <bits/stdc.h>
using namespace std;const int N 110;
int a[N], f[N];int main()
{int t; cin >> t;while (t -- ){static int n;scanf("%…
Educational Codeforces Round 103 (Rated for Div. 2)
A. K-divisible Sum
原题信息 解题思路 AC代码
#include <bits/stdc.h>
using namespace std;typedef long long LL;
const int N 100010;int main()
{int t; cin >> t;while (t -- ){static LL n, k;sc…