摘要:
#include<stdio.h>#include<string.h>int dir[4][2]={{1,0},{0,1},{-1,0},{0,-1}};char a[100][100];int sum,w,h;void sousuo(int x,int y){ int next_x,next_y; for(int i=0;i<=3;i++) { next_x=x+dir[i][0]; next_y=y+dir[i][1]; if(next_x<0||next_x>=h||next_y<0||next_y>=w) continue; if( 阅读全文
posted @ 2013-04-14 15:49
宛如
阅读(106)
评论(0)
推荐(0)
摘要:
#include<stdio.h>#include<string.h>int dir[8][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{-1,-1},{1,-1},{-1,1}};int z;char a[110][110];int b[110][110];void sousuo(int xi,int xj){ for(int i=0;i<=7;i++) { if(a[xi+dir[i][0]][xj+dir[i][1]]=='@'&&b[xi+dir[i][0]][xj+dir[i][1]]==0) 阅读全文
posted @ 2013-04-14 15:48
宛如
阅读(132)
评论(0)
推荐(0)
摘要:
//也可以用生成树的思想做,但要注意是有向边 //生成树的做法:http://blog.sina.com.cn/s/blog_64107d290100h59k.html#include<stdio.h>#include<string.h>int s,e,flag;int vis[10009],map[1009][1009];void dfs(int a){ int i; if(a==e) flag=1; if(flag) return; vis[a]=1; for(i=0;i<26;i++) { if(map[a][i]&&!vis[i]) dfs 阅读全文
posted @ 2013-04-14 15:47
宛如
阅读(164)
评论(0)
推荐(0)
摘要:
#include<stdio.h>int n;int a[50],b[25],c[25];void dfs(int j){ int i; if(j==n&&a[c[n]+1]==1) { for(i=1;i<=n;i++) { if(i==1)printf("%d",c[i]); else printf(" %d",c[i]); } printf("\n"); } for(i=2;i<=n;i++)//将剩下的未选的数历遍查找符合条件的,都查找过了就会结束 { if(b[i]!=0&&a 阅读全文
posted @ 2013-04-14 15:45
宛如
阅读(129)
评论(0)
推荐(0)
摘要:
奇偶剪枝:把map看作0 1 0 1 0 11 0 1 0 1 00 1 0 1 0 11 0 1 0 1 00 1 0 1 0 1从 0->1 需要奇数步从 1->0 需要偶数步那么设所在位置 (si,sj) 与 目标位置 (di,dj)如果abs(si-sj)+abs(di-dj)为偶数,则说明 abs(si-sj) 和 abs(di-dj)的奇偶性相同,需要走偶数步如果abs(si-sj)+abs(di-dj)为奇数,那么说明 abs(si-sj) 和 abs(di-dj)的奇偶性不同,需要走奇数步理解为 abs(si-sj)+abs(di-dj) 的奇偶性就确定了所需要的步 阅读全文
posted @ 2013-04-14 15:44
宛如
阅读(206)
评论(0)
推荐(0)
摘要:
BFS+标记最小转弯次数http://blog.csdn.net/zhuhuangjian/article/details/8262561http://www.cnblogs.com/g0feng/archive/2012/09/02/2667644.html这题的解法就是对四个方向 BFS, 但不是一步一步 , 也就是搜一个方向的时候一直搜索到沿这个方向能走到的尽头 ,这样搜的话 , 能够保证搜过的路径的转弯次数都是最小的#include<stdio.h>#include<queue>#include<string.h> #include<queue 阅读全文
posted @ 2013-04-14 15:38
宛如
阅读(166)
评论(0)
推荐(0)
摘要:
#include <stdio.h>#define MAX_ 100000;char map[100][100];typedef struct { int x ,y ,time ,front; }point;int dir[4][2] = {-1,0,0,1,1,0,0,-1} ,mintime[100][100];int n , m ,I ,J;point arr[1000000];void bfs (){ while (I != J)//队列不为空 { point head = arr[I++]; fo... 阅读全文
posted @ 2013-04-14 15:22
宛如
阅读(153)
评论(0)
推荐(0)
摘要:
广搜的全称为广度优先搜索,会用到队列结构中增加char类型的key[26],会MLE(超内存);所以用二进制来表示手头的钥匙100表示有第3把,111表示有第3,2,1把钥匙,如果该点为钥匙点,则可采用|运算来模拟拾取,显然0001|1000 = 1001,同理,当为相应的门时采用&运算来模拟开启,例如1101 & 0001 = 0001(即可以打开'A'门)#include<stdio.h>#include<queue>using namespace std;//定义队列一定要写这个 int n,m,t;char map[21][21] 阅读全文
posted @ 2013-04-14 15:10
宛如
阅读(149)
评论(0)
推荐(0)

浙公网安备 33010602011771号