上一页 1 ··· 17 18 19 20 21 22 23 24 25 ··· 30 下一页
  2012年8月21日
摘要: 数学题。去网上看了别人的思路。假设A中去掉的数在第k+1位,可以把A分成三部分,低位,k,和高位。A == a + b * 10^k + c * 10^(k+1)B == a + c * 10^kN == A + B == 2 * a + b * 10^k + c * 10^k * 11 其中b是一位数,b*10^k不会进位,用10^k除N取整就可以得到b + 11c,再用11除,商和余数就分别是c和b了。但是这里有个问题a是一个小于10^k的数没错,但是2*a有可能产生进位,如果用A/10^k的话,这样就影响了刚才求出来的b + 11c。但是没有关系,因为2*a进位最多为1,也就是b可能实际 阅读全文
posted @ 2012-08-21 21:34 有间博客 阅读(307) 评论(0) 推荐(0) 编辑
摘要: 简单模拟。CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>usingnamespacestd;constintSIZE=101;charstr[SIZE];charsave[SIZE];intflag;voidreverse(char*str){inti;intlen=strlen(str);for(i=0;i<len/2;i++){chartmp=str[len-i-1];str[len-i-1]=str[i];str[i]=tmp;}re 阅读全文
posted @ 2012-08-21 14:49 有间博客 阅读(171) 评论(0) 推荐(0) 编辑
  2012年8月19日
摘要: 优先队列+BFS的经典题型。CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>#include<queue>usingnamespacestd;#defineSIZE201#defineINF0x0fffffffconstintmove[4][2]={{1,0},{-1,0},{0,-1},{0,1}};charmaze[SIZE][SIZE];intTime[SIZE][SIZE];intN,M;intbx,by,ex,ey;structnode{friendbooloperat 阅读全文
posted @ 2012-08-19 18:54 有间博客 阅读(250) 评论(0) 推荐(0) 编辑
摘要: 简单搜索。DFS求图有几个连通分量。CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>usingnamespacestd;constintSIZE=110;constintmove[8][2]={{-1,-1},{-1,0},{-1,1},{0,1},{0,-1},{1,1},{1,0},{1,-1}};charmaze[SIZE][SIZE];intN,M;intcheck(intr,intc){if(maze[r][c]!='*' 阅读全文
posted @ 2012-08-19 15:58 有间博客 阅读(131) 评论(0) 推荐(0) 编辑
摘要: 简单搜索题,由于很久没写搜索题的缘故,我自己的模板出现了小问题。注意:1、如果maze[q.x][q.y] == 4的话可能会出现死循环,所以要走过之后直接标记为0。CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>#include<queue>usingnamespacestd;constintSIZE=110;intmaze[SIZE][SIZE];constintmove[4][2]={{1,0},{-1,0},{0,-1},{0,1}};intflag[SIZE][SIZE 阅读全文
posted @ 2012-08-19 12:02 有间博客 阅读(199) 评论(0) 推荐(0) 编辑
  2012年8月18日
摘要: 简单搜索题。关键是搜索状态的确定以及判断是否重复的方法。记得回溯,可能存在多种解但不一定是最大的。1、状态从左至右,从上至下去搜索的。2、由于是从上之下,从左至右搜索的,所以是要判断是否重复就看头顶上是否存在炮点,左手边是否存在炮点就行了。CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>usingnamespacestd;constintSIZE=6;intMAX;intmaze[SIZE][SIZE];intN;intcheck(intr,int 阅读全文
posted @ 2012-08-18 21:23 有间博客 阅读(177) 评论(0) 推荐(0) 编辑
  2012年8月17日
摘要: 由于数据比较弱,所以没用欧拉函数直接枚举也可以过。思路:n为1或者n为2的倍数时一定不存在,为奇数时一定存在。 (ab) % n = (a%n * b%n) % n;CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>usingnamespacestd;intmain(){intn;while(~scanf("%d",&n)){inti;if(n==1||n%2==0){printf("2^?mod%d=1\n",n);continue;}long 阅读全文
posted @ 2012-08-17 09:58 有间博客 阅读(136) 评论(0) 推荐(0) 编辑
摘要: 简单的最小生成树问题,关键在于建图的正确性。CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>#include<algorithm>usingnamespacestd;constintSIZE=110;structnode{intu,v,w;}edge[SIZE*SIZE];intp[SIZE];intfind(intx){returnp[x]==x?x:p[x]=find(p[x]);}intcmp(constnodea,constnodeb){returna.w<=b.w 阅读全文
posted @ 2012-08-17 08:59 有间博客 阅读(132) 评论(0) 推荐(0) 编辑
  2012年8月12日
摘要: 思路:第一次写的时候是通过循环移位加KMP算法,结果超时了。第二次写直接将第一个字符串接在第一个字符串的后面。引用:该题请求一个串轮回后是否包含别的一个串,其实只要将母串反复一次再进行KMP匹配就行了,因为在反复母串的过程中,其实据已经将轮回后的所有可能都列举出来了,比如串 "ABCD" 反复后为 "ABCDABCD" 在这个串中 "BCDA" , "CDAB" 以及 "DABC" 都接踵呈现了。用该种办法求解的过程中还应重视当子串长度跨越母串时不进行匹配,因为那样可能输失足误的断定,比如上例中 阅读全文
posted @ 2012-08-12 10:06 有间博客 阅读(1175) 评论(0) 推荐(0) 编辑
  2012年8月10日
摘要: KMP模板题目。CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>usingnamespacestd;__int64a[1000001];__int64b[10001];intnextval[10001];__int64N,M;intget(__int64a[],__int64b[],intpos){__int64i,j;i=pos;j=1;while(i<=a[0]&&j<=b[0]){if(a[i]==b[j]||j==0){i++;j++;}elsej=nex 阅读全文
posted @ 2012-08-10 16:27 有间博客 阅读(200) 评论(0) 推荐(0) 编辑
上一页 1 ··· 17 18 19 20 21 22 23 24 25 ··· 30 下一页