2012年7月18日
摘要: 简单模拟: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) 编辑
  2012年7月17日
摘要: 先前的思路是观察1-10的数,可以用纯暴力从2,6,10一直循环到1000000从而找出自身数,但是会超时。于是我就想,从一个数算出下一个数,如132->138,通过138->150这样由一个数得到另一个数。这样类似于筛选法,而且只要循环一边就可以得到答案了。CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>#defineMAX_1000001usingnamespacestd;constintSIZE=1000001;intvis[SIZE]={0};voidinit(intn) 阅读全文
posted @ 2012-07-17 21:26 有间博客 阅读(150) 评论(0) 推荐(0) 编辑
摘要: 题意要理解好。分割后的整数有若干零,则输出零。CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>usingnamespacestd;constintmaxn=1001;chars[maxn],save[maxn];inta[maxn];intcmp(constvoid*a,constvoid*b){return*(int*)a-*(int*)b;}intmain(){inti,j;while(~scanf("%s",s)){intl=strlen(s);inttot1=0; 阅读全文
posted @ 2012-07-17 20:40 有间博客 阅读(136) 评论(0) 推荐(0) 编辑
摘要: 简单模拟:CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>usingnamespacestd;chars[81];intmain(){intfirst=1;//判断是否是在行首intcnt=0;while(~scanf("%s",s)){inti,j;if(!strcmp(s,"<br>")){printf("\n");cnt=0;first=1;//每次换行后下一行必定在行首,所以first=1;continue;}i 阅读全文
posted @ 2012-07-17 16:39 有间博客 阅读(116) 评论(0) 推荐(0) 编辑
摘要: 同余定理的运用:(a+b)%c=(a%c+b%c)%c;(a*b)%c=(a%c*b%c)%c;CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>usingnamespacestd;constintmaxn=1001;chars[maxn];intmain(){intm;while(~scanf("%s%d",s,&m)){intl=strlen(s);intans=0;for(inti=0;i<l;i++){ans=(ans*10%m+(s[i]-' 阅读全文
posted @ 2012-07-17 15:45 有间博客 阅读(87) 评论(0) 推荐(0) 编辑