T1:
一个脑洞很大的题,将输入的所有数异或起来输出就好了;
(话说我为什么这么喜欢用异或啊)
#include<bits/stdc++.h> using namespace std; inline int read(){ int ans=0; char last=' ',ch=getchar(); while(ch>'9'||ch<'0') last=ch,ch=getchar(); while(ch>='0'&&ch<='9') ans=(ans<<1)+(ans<<3)+ch-'0',ch=getchar(); if(last=='-') ans=-ans; return ans; } int n,c; int ans; int main(){ n=read(); for(int i=1;i<=n;i++){ c=read(); ans^=c; } printf("%d",ans); return 0; }
T2:
结论题:当某个字符串长度恰巧为3^k+1时,从它往下的第3^k+1行恰好只决定于这个字符串的左右两个端点的值;
#include<bits/stdc++.h> using namespace std; inline int read() { int ans=0; char last=' ',ch=getchar(); while(ch>'9'||ch<'0') last=ch,ch=getchar(); while(ch>='0'&&ch<='9') ans=(ans<<1)+(ans<<3)+ch-'0',ch=getchar(); if(last=='-') ans=-ans; return ans; } int n,l; char a[10000010]; int three[15]= {2,4,10,28,82,244,730,2188,6562,19684,59050,177148,531442,1594324,4782970}; int main() { n=read(); scanf("%s",a+1); int len=strlen(a+1); while(len>0) { for(int i=14; i>=0; i--) if(three[i]<=len) { l=three[i]; break; } for(int i=1; i<=len-l+1; i++) { if(a[i]==a[i+l-1]) continue; if(a[i]=='B'&&a[i+l-1]=='G') { a[i]='R'; continue; } if(a[i]=='B'&&a[i+l-1]=='R') { a[i]='G'; continue; } if(a[i]=='G'&&a[i+l-1]=='B') { a[i]='R'; continue; } if(a[i]=='G'&&a[i+l-1]=='R') { a[i]='B'; continue; } if(a[i]=='R'&&a[i+l-1]=='B') { a[i]='G'; continue; } if(a[i]=='R'&&a[i+l-1]=='G') { a[i]='B'; continue; } } len=len-l+1; } printf("%c",a[1]); }
然后还有一个暴力骗分的方法,只能得到30pts,但在找不出规律时也不失为一种策略(当然tle的部分你可以随便输出‘R’,‘G’,‘B’中的任意一个,应该也可以骗到不少分);
#include<bits/stdc++.h> using namespace std; inline int read() { int ans=0; char last=' ',ch=getchar(); while(ch>'9'||ch<'0') last=ch,ch=getchar(); while(ch>='0'&&ch<='9') ans=(ans<<1)+(ans<<3)+ch-'0',ch=getchar(); if(last=='-') ans=-ans; return ans; } int n; char a[10000010]; int main() { n=read(); scanf("%s",a+1); int len=strlen(a+1); while(len>4) { for(int i=1; i<=len-3; i++) { if(a[i]==a[i+3]) continue; if(a[i]=='B'&&a[i+3]=='G') { a[i]='R'; continue; } if(a[i]=='B'&&a[i+3]=='R') { a[i]='G'; continue; } if(a[i]=='G'&&a[i+3]=='B') { a[i]='R'; continue; } if(a[i]=='G'&&a[i+3]=='R') { a[i]='B'; continue; } if(a[i]=='R'&&a[i+3]=='B') { a[i]='G'; continue; } if(a[i]=='R'&&a[i+3]=='G') { a[i]='B'; continue; } } len-=3; } if(len==4) { if(a[1]==a[4]) printf("%c",a[1]); if(a[1]=='B'&&a[4]=='G') printf("R"); if(a[1]=='B'&&a[4]=='R') printf("G"); if(a[1]=='G'&&a[4]=='B') printf("R"); if(a[1]=='G'&&a[4]=='R') printf("B"); if(a[1]=='R'&&a[4]=='B') printf("G"); if(a[1]=='R'&&a[4]=='G') printf("B"); return 0; } while(len) { for(int i=1; i<=len-1; i++) { if(a[i]==a[i+1]) continue; if(a[i]=='B'&&a[i+1]=='G') { a[i]='R'; continue; } if(a[i]=='B'&&a[i+1]=='R') { a[i]='G'; continue; } if(a[i]=='G'&&a[i+1]=='B') { a[i]='R'; continue; } if(a[i]=='G'&&a[i+1]=='R') { a[i]='B'; continue; } if(a[i]=='R'&&a[i+1]=='B') { a[i]='G'; continue; } if(a[i]=='R'&&a[i+1]=='G') { a[i]='B'; continue; } } len--; } printf("%c",a[1]); return 0; }