标签:style blog http color io os ar for 2014
字符串比较
1 #include<cstdio> 2 char a[110]; 3 char A[]="MAI MAI MAI!"; 4 char B[]="SONY DAFA IS GOOD!"; 5 char apple[4][8]={"Apple","iPhone","iPod","iPad"}; 6 char sony[]="Sony"; 7 bool judge(char my[],int s){ 8 for(int i=0;my[i];i++){ 9 if(my[i]!=a[s+i]) return false; 10 } 11 return true; 12 } 13 int main(){ 14 while(gets(a)){ 15 for(int i=0;a[i];i++){ 16 if(judge(sony,i)){ 17 puts(B); 18 continue; 19 } 20 for(int j=0;j<4;j++){ 21 if(judge(apple[j],i)){ 22 puts(A); 23 break; 24 } 25 } 26 } 27 } 28 return 0; 29 }
用的是尼姆博弈的结论,至于为什么和原来的尼姆博弈的结论是一样一样的,有待证明。
1 #include<cstdio> 2 int main(){ 3 int n,a; 4 while(~scanf("%d",&n)){ 5 int ans=0; 6 while(n--){ 7 scanf("%d",&a); 8 ans^=a; 9 } 10 if(ans) puts("Win"); 11 else puts("Lose"); 12 } 13 return 0; 14 }
bfs 4个方向转,把转的置换写出来会比较好。用string表示状态,用map来判重,会方便很多,但是c++会ce,用g++交就ac,也是有点坑。
1 #include<cstdio> 2 #include<iostream> 3 #include<queue> 4 #include<map> 5 using namespace std; 6 string S,E; 7 map<string,bool> vis; 8 struct Q{ 9 int step; 10 string sta; 11 }now,pre; 12 queue<Q> q; 13 int zhuan[4][8]={ 14 {2,3,1,0,4,5}, 15 {3,2,0,1,4,5}, 16 {4,5,2,3,1,0}, 17 {5,4,2,3,0,1}, 18 }; 19 int bfs(){ 20 vis.clear(); 21 vis[S]=true; 22 now.sta=S; 23 now.step=0; 24 while(!q.empty()) q.pop(); 25 q.push(now); 26 while(!q.empty()){ 27 pre=q.front(); 28 q.pop(); 29 if(pre.sta==E) return pre.step; 30 for(int i=0;i<4;i++){ 31 for(int j=0;j<6;j++){ 32 now.sta[j]=pre.sta[zhuan[i][j]]; 33 } 34 now.sta.resize(6); 35 if(!vis[now.sta]){ 36 vis[now.sta]=true; 37 now.step=pre.step+1; 38 q.push(now); 39 } 40 } 41 } 42 return -1; 43 } 44 int main(){ 45 char op[2]; 46 while(~scanf("%s",op)){ 47 S=op[0]; 48 for(int i=1;i<6;i++){ 49 scanf("%s",op); 50 S+=op[0]; 51 } 52 E=""; 53 for(int i=0;i<6;i++){ 54 scanf("%s",op); 55 E+=op[0]; 56 } 57 printf("%d\n",bfs()); 58 } 59 return 0; 60 }
end
2014 ACM/ICPC Asia Regional Xi'an Online
标签:style blog http color io os ar for 2014
原文地址:http://www.cnblogs.com/gaolzzxin/p/3971423.html