文章分类 -  bfs

摘要:hdu1372: http://acm.hdu.edu.cn/showproblem.php?pid=1372题意:一张8*8棋盘,横坐标用a~h表示,纵坐标用1~8表示,每对数据给出马的初始位置和目标位置,问需要多少步能到达code:#include<iostream>#include<cstdio>#include<cstdlib>#include<algorithm>using namespace std;int dx[]={-2,2,-1,1,-2,2,-1,1};int dy[]={1,-1,-2,-2,-1,1,2,2};int q[ 阅读全文

posted @ 2012-07-26 12:17 acmer-jun 阅读(172) 评论(0) 推荐(0)

摘要:hdu2579: http://acm.hdu.edu.cn/showproblem.php?pid=2579题意:“#”代表石头,如果走的步数是k的倍数,石头会消失,求最小时间(步数)code:#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>using namespace std;const int inf=1<<29;char v[150][150];int q[150*150*150][2], 阅读全文

posted @ 2012-07-26 12:10 acmer-jun 阅读(166) 评论(0) 推荐(0)

摘要:hdu2102: http://acm.hdu.edu.cn/showproblem.php?pid=2102 题意:迷宫的入口是S(0,0,0),公主的位置用P表示,时空传输机用#表示,墙用*表示,平地用.表示。骑士们一进入时空传输机就会被转到另一层的相对位置,但如果被转到的位置是墙 的话,那骑士们就会被撞死。骑士们在一层中只能前后左右移动,每移动一格花1时刻。层间的移动只能通过时空传输机,且不需要任何时间。code:#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib 阅读全文

posted @ 2012-07-26 12:07 acmer-jun 阅读(181) 评论(0) 推荐(0)

摘要:hdu1728: http://acm.hdu.edu.cn/showproblem.php?pid=1728题意:求最少转弯数,开始时方向不定,所以第一次算不成转弯code:#include<iostream>#include<cstdio>#include<cstdlib>int dx[]={1,-1,0,0};int dy[]={0,0,1,-1};int q[150*600][2],d[150][150][4];char v[150][150];const int inf=1<<29;int main(){ int i,j,m,n,x,y 阅读全文

posted @ 2012-07-26 12:02 acmer-jun 阅读(188) 评论(0) 推荐(0)

摘要:hdu1548: http://acm.hdu.edu.cn/showproblem.php?pid=1548题意:坐电梯,给出层数n,求从a到b最少要按多少次键(每层楼有一个数c[i],表示可以搭到第i-c[i]和第i+c[i]层,但只能到达1至n层,求最少需要按多少次按钮可到达目的地。解法:bfs(也可用dij求最短路)code:#include<iostream>#include<cstdio>#include<cstdlib>int v[250][250],k[250],d[250],q[3000*300];const int inf=2<&l 阅读全文

posted @ 2012-07-25 17:27 acmer-jun 阅读(143) 评论(0) 推荐(0)

摘要:hdu1195: http://acm.hdu.edu.cn/showproblem.php?pid=1195题意:求解密最少步骤:密码为四位数,每次操作可将一个数加一或减一(1减一变为9,9加一变为1),也可互换相邻数字,求最少需要多少操作数能解密解法:bfs:加一减一和交换位置都属于状态转移code:#include<iostream>#include<cstdio>#include<cstdlib>int q[1000*1000][4],v[4],key[4],dis[10][10][10][10],an1[4],bn1[4],cn1[4],dn1[4 阅读全文

posted @ 2012-07-25 16:44 acmer-jun 阅读(178) 评论(0) 推荐(0)

摘要:hdu1253: http://acm.hdu.edu.cn/showproblem.php?pid=1253题意:3层迷宫:一个A*B*C的立方体,可以被表示成A个B*C的矩阵,要从(0,0,0)到(A-1,B-1,C-1),若时间小于t,输出时间,否则输出-1.解法:bfs:开三维数组d[i][j][k]表示在第k个矩阵的点(i,j)上,队列要进点和k。code:#include<iostream>#include<cstdio>#include<cstdlib>int d[60][60][60];char v[60][60][120];struct a 阅读全文

posted @ 2012-07-25 16:40 acmer-jun 阅读(156) 评论(0) 推荐(0)

摘要:hdu1072: http://acm.hdu.edu.cn/showproblem.php?pid=1072题意:0代表墙,1代表空地,2代表始点,3代表终点,4代码时间重置,炸弹限时6s,每走一步耗时1s,如果到达4可重置为6s,求最少逃脱时间,逃脱不了输出-1解法:bfs:开三维数组d[i][j][k]表示到达(i,j)点时剩余时间为k,此时的最优值,队列开二维q[rear][0]进点,q[rear][1]进剩余时间code:#include<iostream>#include<cstdio>#include<cstdlib>int d[10][10] 阅读全文

posted @ 2012-07-25 16:20 acmer-jun 阅读(173) 评论(0) 推荐(0)

导航