HDU 1372 Knight Moves
来源:互联网 发布:python rexec 的使用 编辑:程序博客网 时间:2024/05/20 18:41
http://acm.hdu.edu.cn/showproblem.php?pid=1372
#include <iostream>#include <cstring>#include <cstdio>#include <cstdlib>#include <queue>using namespace std;struct node{ int xx,yy; int step;}info;char str1[3],str2[3];int dir[8][2]={{2,-1},{1,-2},{2,1},{1,2},{-1,2},{-2,1},{-2,-1},{-1,-2}};int map[10][10];int x1,x2,y1,y2;int flag;void bfs(int x,int y){ info.xx=x; info.yy=y; info.step=0; map[x][y]=1; queue<node> q; q.push(info); while(!q.empty()){ node temp=q.front(); q.pop(); if( temp.xx==x2 && temp.yy==y2){ printf("To get from %s to %s takes %d knight moves.\n",str1,str2,temp.step); return ; } for(int i=0;i<8;i++){ int xx=temp.xx+dir[i][0]; int yy=temp.yy+dir[i][1]; int step=temp.step+1; if( xx>=0 && xx<8 && yy>=0 && yy<8 && map[xx][yy]==0){ info.xx=xx; info.yy=yy; info.step=step; map[xx][yy]=1; q.push(info); //printf("step=%d i=%d xx=%d yy=%d\n",step,i,xx,yy); } } }}int main(){ while(scanf("%s %s",&str1,&str2)!=EOF){ x1=str1[0]-97; y1=str1[1]-'0'-1; x2=(int)(str2[0]-97); y2=str2[1]-'0'-1; //printf("%d %d %d %d\n",x1,y1,x2,y2); memset(map,0,sizeof(map)); bfs(x1,y1); } return 0;}
0 0
- HDU 1372 knight moves
- HDU 1372 Knight Moves
- HDU-1372-Knight Moves
- hdu 1372 Knight Moves
- HDU 1372 Knight Moves
- hdu 1372 Knight Moves
- Hdu 1372 Knight Moves
- HDU 1372 Knight Moves
- HDU 1372 Knight Moves
- HDU-1372Knight Moves
- HDU-1372-Knight Moves
- hdu 1372 Knight Moves
- hdu-1372-Knight Moves
- HDU 1372 Knight Moves
- HDU-1372-knight moves
- hdu(1372) Knight Moves
- hdu 1372 Knight Moves
- hdu 1372 Knight Moves
- Java Web
- Robots递归,模拟,规律
- 使用原生js制作轮播图
- redis.conf配置详解
- CI 配置
- HDU 1372 Knight Moves
- clion active code
- c++网络库libevent简介
- 实现两个程序mysignal、mycontrl,mycontrl给mysignal发送SIGINT信号,控制mysignal是否在屏幕打印“hello”字符串。
- Html.DisplayNameFor等强类型辅助方法不识别
- Android100天学习小结
- adb不是内部或外部命令,也不是可运行的程序或批量文件
- JAVA基础知识
- MySql-半同步复制