随笔分类 - bfs
摘要:http://poj.org/problem?id=3669题意:给定几个坐标,在这些坐标上 t 时刻会有陨石雨,上下左右也被损坏。怎样在最短的时间内找到一个安全的地方。思路:预处理每个陨石下落的周围的点,然后bfs就可以。 1 #include 2 #include 3 #include 4...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1732推箱子和游戏规则一样。 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 char g[10...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1104a%b=(a%b+b)%b;题意:开始给了你n, k, m,每次由+m, -m, *m, modm得到新的N,继续对N这样的操作,直到(n+1) mod k== N mod k时结束,并且打印路径 1 #in...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1548 1 #include 2 #include 3 #include 4 #include 5 #include 6 #define maxn 300 7 using namespace std; 8...
阅读全文
摘要:http://acm.timus.ru/problem.aspx?space=1&num=1119 1 #include 2 #include 3 #include 4 #include 5 #include 6 #define maxn 1010 7 using namespace std; 8 9 int head[maxn],e,n,m;10 int dir[4][2]={{0,-1},{0,1},{1,0},{-1,0}};11 bool vis[maxn][maxn];12 bool visi[maxn][maxn];13 double step;14 15 struct..
阅读全文
摘要:http://acm.timus.ru/problem.aspx?space=1&num=1837 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 using namespace std; 9 vectorq[500]; 10 11 struct node 12 { 13 string s; 14 int num; 15 bool operator qq; 35 bool vis[50000]; 36 memse...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1429 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 char g[100][100]; 7 int vis[30][30][1026]; 8 int a[4][2]={{-1,0},{1,0},{0,-1},{0,1}}; 9 int n,m,sx,sy,ex,ey,step; 10 11 struct node 12 { 13 int x,y,k,step; 14 }st,st1; 15...
阅读全文
摘要:http://poj.org/problem?id=1606 1 #include 2 #include 3 #define MAXN 1000000 4 using namespace std; 5 6 int c,d,e,ans,l; 7 bool vis[1001][1001]; 8 struct node 9 { 10 int a,b; 11 int flag; 12 int pre; 13 int step; 14 }p[MAXN],st,st1; 15 16 void bfs() 17 { 18 p[0].a=0; 19...
阅读全文
摘要:http://poj.org/problem?id=3414 1 #include 2 #include 3 #define MAXN 1000000 4 using namespace std; 5 6 int c,d,e,ans,l; 7 bool vis[120][120]; 8 struct node 9 { 10 int a,b; 11 int flag; 12 int pre; 13 int step; 14 }p[MAXN],st,st1; 15 16 void bfs() 17 { 18 p[0].a=0; 19 ...
阅读全文
摘要:1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #define MAXN 40 8 using namespace std; 9 10 char map[MAXN][MAXN][MAXN];11 bool vis[MAXN][MAXN][MAXN];12 int s[][10]= {{1,0,0},{-1,0,0},{0,1,0},{0,-1,0},{0,0,1},{0,0,-1}};13 int ex,ey,ez,sx,sy,sz,zz,yy,xx,l,r,c,k;14 struct node15 {1.
阅读全文
摘要:http://poj.org/problem?id=3126 1 #include 2 #include 3 #include 4 using namespace std; 5 6 struct node 7 { 8 int k,step; 9 };10 11 node h[100000];12 bool p[11000];13 int x,y,tot,s[11000];14 15 void make(int n)16 {17 memset(p,0,sizeof(p));18 p[0]=1;19 p[1]=1;20 for(int i=2; i>tot...
阅读全文