uva 439
来源:互联网 发布:战队图标制作软件 编辑:程序博客网 时间:2024/05/15 06:39
//水题 但是多次输入清楚queue元素误用if(!queue.empty()),应为while,浪费很多时间,注意
#include<iostream>
#include<queue>
#include<algorithm>
#include<map>
#include<string.h>
#include<math.h>
#include<stdio.h>
#include <iomanip>
#include <stack>
#include <vector>
#include <sstream>
////////
using namespacestd;
typedef pair<int,int>p;
queue<p>que;
int chessboard[8][8];
string start,ending;
int sx,sy;
int ex,ey;
int dx[] = { -1, -1,1, 1, -2, -2,2, 2 };
int dy[] = { 2, -2,2, -2,1, -1,1, -1 };
void solve()
{
int x,y;
int i,j;
chessboard[sx][sy]=0;
while(!que.empty())
{
p temp =que.front();
que.pop();
if(temp.first==ex && temp.second==ey)
break;
for(i=0;i<8;i++)
{
x=temp.first+dx[i];
y =temp.second+dy[i];
if(0<=x && x<=7 &&0<=y && y<=7)
{
que.push(p(x,y));
chessboard[x][y] =chessboard[temp.first][temp.second]+1;
}
}
}
cout<<"To get from "<<start<<" to "<<ending<<" takes "<<chessboard[ex][ey]<<" knight moves."<<endl;
}
int main()
{
while(cin>>start>>ending)
{
//input
while(!que.empty())
que.pop();
memset(chessboard,0,sizeof(chessboard));
sx =start[0]-'a';
sy =start[1]-'1';
ex =ending[0]-'a';
ey =ending[1]-'1';
que.push(p(sx,sy));
solve();
}
}
- uva 439
- UVa 439
- UVA 439
- uva 439
- uva 439
- uva 439
- uva 439
- UVA------439
- UVA 439
- UVA 439
- uva 439 knight moves
- uva 439 - Knight Moves
- uva 439 - Knight Moves
- uva 439 - Knight Moves
- uva 439 - Knight Moves
- uva-439 - Knight Moves
- UVa 439 - Knight Moves
- UVA 439 骑士游历
- 6.5 GitHub - 脚本 GitHub
- PowerManagerService 核心方法详解(转载,感觉不错)
- String、StringBuffer与StringBuilder之间区别
- A64笔记002
- java实现子串在原串出现的次数
- uva 439
- markdown的语法
- 【软件】Chrome 浏览器下载文件崩溃
- java web 项目 通过 action 查询第三方网址并跳转
- iOS高仿app源码:10天时间纯代码打造高仿优质《内涵段子》
- 忘记NSURLConnection,拥抱NSURLSession吧
- 删除linux文件行尾^M
- markdown的语法规则
- OProfile