CodeForces - 1384
A - Common Prefixes GNU
前缀取相同,后面的不同的字母向后移一位char ans[maxn][60];
int t,n,a[maxn];
int main()
{scanf("%d",&t);while(t--){scanf("%d",&n);rep(i,1,n)scanf("%d",&a[i]);rep(i,1,50)ans[1][i]='a';rep(i,2,n+1){rep(j,1,a[i-1])ans[i][j]=ans[i-1][j];rep(j,a[i-1]+1,50)ans[i][j]=(ans[i-1][a[i-1]+1]-'a'+1)%26+'a';}rep(i,1,n+1){rep(j,1,50)printf("%c",ans[i][j]);puts("");}}return 0;
}
B2 - Koa and the Beach (Hard Version)
h表示当前的高度,f表示h下一步将要-1还是+1int n,t,a[maxn],k,l,h,f;
bool solve()
{int h=k+1,f=-1;rep(i,1,n){if (a[i]<0)return false;else if (a[i]>=k){h=k+1;f=-1;}else if (f==-1)h=min(h-1,a[i]);else{h++;if (h>a[i])return false;}if (h==0)f=1;}return true;
}
int main()
{scanf("%d",&t);while(t--){scanf("%d%d%d",&n,&k,&l);rep(i,1,n)scanf("%d",&a[i]),a[i]=l-a[i];if (solve())printf("YES\n");else printf("NO\n");}return 0;
}
C - String Transformation 1
直接模拟
S[x-'a'].insert(y-'a')表示x需要转化为yabb
bcd
a要变成b,b要变成c,b要变成d对a进行操作后:
bbb
bcd
b要变成c,b要变为d对b进行第一次操作后:
bcc
bcd
变为:c要变为d对b进行第二次操作后:
bcd
bcdchar s1[maxn],s2[maxn];
int t,n;
set<int> S[30];
int main()
{scanf("%d",&t);while(t--){rep(i,0,28)S[i].clear();bool mark=true;int ans=0;scanf("%d",&n);scanf("%s",s1);scanf("%s",s2);rep(i,0,n-1){if (s1[i]==s2[i])continue;else if (s1[i]>s2[i])mark=false;else if (S[s1[i]-'a'].find(s2[i]-'a')==S[s1[i]-'a'].end())S[s1[i]-'a'].insert(s2[i]-'a');}rep(i,0,25){if (S[i].size()==0)continue;set<int>:: iterator it;ans++;int x=*S[i].begin();for (it=S[i].begin();it!=S[i].end();it++){if (it==S[i].begin())continue;if (S[x].find(*it)==S[x].end())S[x].insert(*it);}}if (!mark)W(-1);else W(ans);}return 0;
}
D - GameGame
摘自:https://blog.csdn.net/C_Dreamy/article/details/107576085?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522159724017219724848303834%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=159724017219724848303834&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_ecpm_v3~pc_rank_v2-2-107576085.first_rank_ecpm_v3_pc_rank_v2&utm_term=++Codeforces+Round+%23659+%28Div.+&spm=1018.2118.3001.4187
根据异或的性质,统计所有位上的数字a 表示当前位上 1 的个数,b 表示当前位上 0 的个数如果 a 是偶数,无论 b ,这一位上都相同如果 a 是奇数,Koa 先拿,现在有 a-1 个 1,为偶数,很容易想到剩余的 1 该如何分若 均分后每个人再分偶数个 即 (a-1)%4=0,也就是说每个人再分到偶数个 1,那么无论 b, Koa 赢
若 均分后每个人再分奇数个 即 (a-1)%4=2,那么决定权再对手手里,即通过拿 0 使得 Koa 再拿奇数个 1
如果 0 有偶数个,那么 Koa 一定会拿到奇数个 1,一定输
如果 0 有奇数个,那么 Koa 通过多拿一个 0 少拿一个 1,使得对手多拿一个 1 ,从而获得胜利int num1[maxn],num0[maxn],t,n,x;
int main()
{scanf("%d",&t);while(t--){int ans=0;mem(num1,0);scanf("%d",&n);rep(i,1,n){scanf("%d",&x);repp(j,0,30)if (x&(1<<j))num1[j]++;}for (int i=29;i>=0;i--){num0[i]=n-num1[i];if (num1[i]%2==1){if (num1[i]%4==1)ans=1;else if (num1[i]%4==3&&num0[i]%2==0)ans=2;else if (num1[i]%4==3&&num1[i]%2==1)ans=1;break;}}if (ans==1)printf("WIN\n");else if (ans==2)printf("LOSE\n");else printf("DRAW\n");}return 0;
}