HDU 1372——DFS
来源:互联网 发布:淘宝女装精修图教程 编辑:程序博客网 时间:2024/06/05 04:09
DFS的模板题题目链接点击打开链接#include<iostream>#include<cstring>#include<cstdio>#include<queue>#define MM(x,y) memset(x,y,sizeof(x))using namespace std;struct node{ int x; int y; int pos;};queue<node>a;char e[5],s[5];int vis[30][30];int dir[8][2]={{1,2},{2,1},{1,-2},{-2,1},{-1,2},{2,-1},{-1,-2},{-2,-1}};int ex,ey,sx,sy;int dfs(){ while(!a.empty()) a.pop(); int i; node now,next; now.x=sx; now.y=sy; now.pos=0; MM(vis,0); vis[sx][sy]=1; a.push(now); while(!a.empty()) { now=a.front(); a.pop(); if(now.x==ex&&now.y==ey) return now.pos; else { for(i=0;i<8;i++) { int tx=now.x+dir[i][0]; int ty=now.y+dir[i][1]; if(tx>=1&&tx<=8&&ty>=1&&ty<=8&&!vis[tx][ty]) { next.x=tx; next.y=ty; next.pos=now.pos+1; vis[tx][ty]=1; a.push(next); } } } }}int main(){ while(cin>>s>>e) { sx=s[0]-'a'+1; sy=s[1]-'0'; ex=e[0]-'a'+1; ey=e[1]-'0'; cout<<"To get from "<<s<<" to "<<e<<" takes "<<dfs()<<" knight moves."<<endl; } return 0;}
阅读全文
0 0
- HDU 1372——DFS
- 【伪dfs】HDU 2571——命运
- Zipper(HDU 1501) —— DFS
- HDU-1242——DFS+优先队列
- hdu(5305)——Friends(dfs)
- HDU 5546 Ancient Go——dfs
- dfs序——hdu 5692 Snacks
- HDU 1010— DFS+奇偶剪枝
- hdu 1175 连连看 搜索—dfs
- hdu 1016——Prime Ring Problem(DFS)
- hdu 1312——Red and Black(DFS)
- hdu 1010——Tempter of the Bone(DFS)
- hdu 2553——N皇后问题(DFS)
- (step 4.3.5)hdu 1035(Robot Motion——DFS)
- (step4.3.4)hdu 1258(Sum It Up——DFS)
- (step4.3.5)hdu 1501(Zipper——DFS)
- (step4.3.7)hdu 1181(变形课——DFS)
- (step4.3.9)hdu 1584(蜘蛛牌——DFS)
- java 生成多个excel文件并打成zip包供用户下载
- Running "uglify:generated" (uglify) task takes a very long time.
- fedora下搭建hostapd+dhcpd建立Wifi热点
- 2012北航机试小岛面积
- Nginx发布web和配置反向代理
- HDU 1372——DFS
- spring配置文件详解--真的蛮详细
- ServletRequest
- deploy Redis 2.8.x on Centos 6.x
- 【前端插件】自定义分页器
- 蓝桥杯 ADV-182 算法提高 前10名
- 访问修饰符
- 路灯最短距离
- Python学习2-程序编辑和运行