Google Code Jam 2012 Qualification Round

来源:互联网 发布:人工智能打败李世石 编辑:程序博客网 时间:2024/05/18 02:53

Problem A. Speaking in Tongues

简单的加密解密题,字母对应关系需要从题目和样例中得出。

#include <iostream>#include <cstring>#include <cstdio>using namespace std;char map[]="yhesocvxduiglbkrztnwjpfmaq";char st[500],str[500];int main(){int t,i,j;//freopen("d:\\gcj\\a.in","r",stdin);//freopen("d:\\gcj\\a.out","w",stdout);scanf("%d",&t);getchar();for(i=1;i<=t;i++){gets(st);printf("Case #%d: ",i);for(j=0;j<strlen(st);j++)if(st[j]!=' ')str[j]=map[st[j]-'a'];elsestr[j]=st[j];str[j]='\0';puts(str);}return 0;}
Problem B. Dancing With the Googlers

小学数学题,告诉你三个评委的评分总分,让你判断是否存在一个分数大于q。

#include <iostream>#include <cstring>using namespace std;int n,s,p,tol[150];int main(){int t,i,j;//freopen("d:\\gcj\\b.in","r",stdin);//freopen("d:\\gcj\\b.out","w",stdout);scanf("%d",&t);for(i=1;i<=t;i++){scanf("%d%d%d",&n,&s,&p);int cnt=0;for(j=0;j<n;j++){scanf("%d",&tol[j]);if(!p){cnt++;continue;}if(!tol[j] && p)continue;if(tol[j]>=p*3-2)cnt++;if(tol[j]>=p*3-4 && tol[j]<=p*3-3 && s){cnt++;s--;}}printf("Case #%d: ",i);printf("%d\n",cnt);}return 0;}

Problem C. Recycled Numbers

给你一个给定区间,让你判断该区间中有多少对移位排列的数。

#include <iostream>#include <cstring>#include <algorithm>using namespace std;int n,s,p,tol[150];char str[100],st[100],st1[100];int main(){int t,i,j,k,a,b;//freopen("d:\\gcj\\c.in","r",stdin);//freopen("d:\\gcj\\c.out","w",stdout);scanf("%d",&t);for(i=1;i<=t;i++){int cnt=0;scanf("%d%d",&a,&b);for(j=a;j<=b;j++){itoa(j,str,10);int len=strlen(str);st[len-1]=str[0];for(k=1;k<len;k++)st[k-1]=str[k];st[len]='\0';while(strcmp(st,str)!=0){int tmp=atoi(st);if(tmp>=a && tmp<=b)cnt++;strcpy(st1,st);st[len-1]=st1[0];for(k=1;k<len;k++)st[k-1]=st1[k];st[len]='\0';}}printf("Case #%d: ",i);printf("%d\n",cnt/2);}return 0;}

Problem D. Hall of Mirrors

告诉你镜子和人的位置,让你判断人能看到自己多少个镜像。

物理奇差的表示压力很大,张哥给我了解决方案,就是弄的不是很明白,于是还是放弃了。。

看了题解发现张哥果断NB啊。。物理大神就是不一样。。