2012年9月1日
摘要: 题目大意:从一个素数变换到另一个素数最小需要多少步。思路:将所有1000~10000的素数通过打表表示出来,然后依次枚举与s相差一位的数并标记,通过BFS找寻最小步数。CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>#include<queue>usingnamespacestd;intprime[10001];intvis[10001];intflag[10001];inttot;ints,e;structnode{intx,step 阅读全文
posted @ 2012-09-01 21:51 有间博客 阅读(153) 评论(0) 推荐(0) 编辑
摘要: 简单深搜。CODE:#include<iostream>#include<string.h>usingnamespacestd;constintlarge=200030;typedefclass{public:intx;intstep;}pos;intn,k;boolvist[large];posqueue[large];voidBFS(void){inthead,tail;queue[head=tail=0].x=n;queue[tail++].step=0;vist[n]=true;while(head<tail){posw=queue[head++];if( 阅读全文
posted @ 2012-09-01 19:54 有间博客 阅读(134) 评论(0) 推荐(0) 编辑
摘要: 简单搜索题。 注意:回溯时需要减1,否则会WA。CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>usingnamespacestd;constintSIZE=30;intdx[]={1,0,-1,0};intdy[]={0,1,0,-1};charmaze[SIZE][SIZE];intflag[SIZE];intans,n,m,num;intcheck(intx,inty){if(x>=0&&y>=0&&x<n&&y< 阅读全文
posted @ 2012-09-01 17:43 有间博客 阅读(191) 评论(0) 推荐(0) 编辑