hdu 1372 bfs最少棋子步数
来源:互联网 发布:java递归求阶乘 编辑:程序博客网 时间:2024/05/16 17:47
背景:还是熟悉bfs,还是调试之后1Y,看来非要写到滚瓜烂熟了!!!。
学习:1.这里队列里每个元素是除了坐标还有步数的结构体。
我的代码:
#include<cstdio>#include<iostream>#include<cstring>#include<queue>using namespace std;int diagram[8][8];struct place{int x,y,count;}temp1,temp2,temp3;int dir[8][2]={2,1,2,-1,1,2,1,-2,-2,1,-2,-1,-1,2,-1,-2};int main(void){ char a,b; while(~scanf("%c%d %c%d%*c",&a,&temp1.x,&b,&temp2.x)){ int key=temp1.x,key1=temp2.x; memset(diagram,1,sizeof(diagram)); temp1.y=a-'a'; temp1.x--; temp2.x--; temp2.y=b-'a'; queue<place> q; temp1.count=0; q.push(temp1); diagram[temp1.x][temp1.y]=0; while(!q.empty()){ temp1=q.front(); //printf("****\n%d\n****\n",temp1.count); q.pop(); if(temp1.x == temp2.x && temp1.y == temp2.y){printf("To get from %c%d to %c%d takes %d knight moves.\n",a,key,b,key1,temp1.count);break;} for(int i=0;i < 8;i++){ temp3.x=temp1.x+dir[i][0]; temp3.y=temp1.y+dir[i][1]; if(temp3.x >=0 && temp3.x < 8 && temp3.y >= 0 && temp3.y < 8 && diagram[temp3.x][temp3.y]){ temp3.count=temp1.count+1; diagram[temp3.x][temp3.y]=0; q.push(temp3); } } } } return 0;}
0 0
- hdu 1372 bfs最少棋子步数
- 最少步数BFS
- 最少步数 【BFS】
- 最少步数(BFS)
- NYOJ - 最少步数【BFS】
- 最少步数(bfs)
- NYOJ58最少步数(BFS)
- 最少步数 bfs样板
- 58 最少步数【bfs】
- nyoj58最少步数bfs
- NYOJ_58最少步数(queue+BFS)
- NYOJ 58 最少步数 【BFS】
- NYOJ 最少步数 58(BFS)
- nyoj 58 最少步数(BFS)
- NYOJ 58 最少步数(BFS)
- NYOJ 58 最少步数(bfs)
- NY 题目58 最少步数 【BFS】
- nyoj 58 最少步数 【BFS】
- win7系统 telnet不是内部或外部命令
- struts2请求过程源码分析
- 使用Fragment和TranslateAnimation详解
- Cocos2d-x 3.x学习记录
- PE 1 Multiples of 3 and 5
- hdu 1372 bfs最少棋子步数
- 【ACM之旅】球队排名
- 老外写的系统统计脚本
- 无上限多例类(Multiton)
- SQLSERVER 三值逻辑
- 1.flume简介
- 数据库用户和权限
- 若干最小路径覆盖问题
- EasyUI-DataGrid多行动态选择性合并算法实现