2012年7月18日
摘要: 简单模拟题。CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>usingnamespacestd;intcheck(inta,intb,intk){inti,j;intsum1=0,sum2=0;for(i=0;i<k;i++){intx=a%10;inty=b%10;if(x!=y){return0;}else{sum1+=x;sum2+=y;a/=10;b/=10;}}if(sum1==sum2)return1;}intmain(){inta,b,k;while(~scanf(&qu 阅读全文
posted @ 2012-07-18 22:18 有间博客 阅读(184) 评论(0) 推荐(0) 编辑
摘要: 简单模拟题。找规律,只要最大的那个数max-(s-max)<=1即可全部吃完。CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>usingnamespacestd;constintmaxn=1000001;inta[maxn];intmain(){intT;intn;__int64s;//定义为__int64,要不会WAscanf("%d",&T);while(T--){inti;s=0;__int64max=-1; 阅读全文
posted @ 2012-07-18 21:30 有间博客 阅读(110) 评论(0) 推荐(0) 编辑
摘要: 简单模拟:CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>#include<algorithm>#include<stack>#include<ctype.h>#definemin2000#definemax10000usingnamespacestd;constintmaxn=101;chars1[maxn],s2[maxn];inttot1,tot2;intinit(intx)//计算一个数的树根之和{intsum=0;while(x){sum+=x% 阅读全文
posted @ 2012-07-18 17:12 有间博客 阅读(238) 评论(0) 推荐(0) 编辑
摘要: 简单模拟。CODE:#include<stdio.h>#include<string.h>#include<stdlib.h>usingnamespacestd;constintmaxn=101;chars[maxn][maxn];intmain(){intc;intcnt;charstr[201];while(~scanf("%d",&c),c){inti,j;scanf("%s",str);intl=strlen(str)/c;cnt=0;for(i=0;i<l;i++){if(i%2==0){for 阅读全文
posted @ 2012-07-18 16:09 有间博客 阅读(132) 评论(0) 推荐(0) 编辑
摘要: 简单模拟。CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>usingnamespacestd;inta[16];intcmp(constvoid*a,constvoid*b){return*(int*)a-*(int*)b;}intmain(){intn;inttot=0,sum=0;while(scanf("%d",&n)){inti,j;if(n==-1)break;if(n){a[tot++]=n;}else{qsort(a,tot,sizeof(int), 阅读全文
posted @ 2012-07-18 13:45 有间博客 阅读(167) 评论(0) 推荐(0) 编辑
摘要: 思路:异或运算的运用,破译密码时一定存在一个大写字母使得所有的原文在'A'~'Z'之内。异或运算法则: 1. a ^ b = b ^ a 2. a ^ b ^ c = a ^ (b ^ c) = (a ^ b) ^ c; 3. d = a ^ b ^ c 可以推出 a = d ^ b ^ c. 4. a ^ b ^ a = b. 相关链接(http://acm.hdu.edu.cn/showproblem.php?pid=1287)CODE:#include<stdio.h>#include<stdlib.h>#include<st 阅读全文
posted @ 2012-07-18 13:30 有间博客 阅读(378) 评论(1) 推荐(0) 编辑
摘要: 思路:首先看能兑换多少个三分硬币的,然后当三分硬币分别为1,2,3,.... n时有多少个2分硬币的,为什么要这样确定了?因为只要还可以兑换出三分硬币和二分硬币的那么剩下的价值一定可以让价值为1的硬币塞满。开头为什么s为N/3+1呢?因为可以这样想,假设N=7,那么只包含3分硬币和1分硬币的组合方式为:3,3,1; 3,1,1,1,1;所以N/3是实际上可以容纳三分硬币的个数。而增加1是因为可以全部换成1分的硬币。有人会疑问,那么t = (N-3*i)/2不是会重复吗?这是不可能的,因为硬币的价值是递增的,只有当i的值为N/3时,t的值可以为0或者1。所以不会重复。CODE:#include& 阅读全文
posted @ 2012-07-18 11:12 有间博客 阅读(236) 评论(0) 推荐(0) 编辑
摘要: 简单模拟。CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>usingnamespacestd;constintmaxn=101;chars[maxn];intnum[2000],cnt;intis_hw(intx)//是否是回文数{inti;sprintf(s,"%d",x);intl=strlen(s);intok=1;for(i=0;i<l;i++){if(s[i]!=s[l-i-1]){ok=0;break;}}if(ok)return1;return0;}i 阅读全文
posted @ 2012-07-18 10:36 有间博客 阅读(262) 评论(0) 推荐(0) 编辑