码迷,mamicode.com
首页 > 编程语言 > 详细

跳马问题一(C++)

时间:2016-11-01 23:51:19      阅读:287      评论:0      收藏:0      [点我收藏+]

标签:space   out   c++   names   using   push   front   cout   exit   

#include<iostream>
#include<queue>
using namespace std;
queue <int> x;
queue <int> y;
int m, n, opx, opy, edx, edy, f[110][110];
int bfs()
{
if((x.empty()) || (y.empty()))
{
cout<<"no";
exit(0);
}
int x1=x.front(),y1=y.front();
x.pop();
y.pop();
if((x1==edx) && (y1==edy))
{
cout<<"yes";
exit(0);
}
if((f[x1][y1]==0) && (x1<n) && (x1>=0) && (y1<m) && (y1>=0))
{
f[x1][y1]=1;
x.push(x1+2);
y.push(y1-1);
x.push(x1+2);
y.push(y1+1);
x.push(x1+1);
y.push(y1+2);
x.push(x1+1);
y.push(y1-2);
}
bfs();
}
int main()
{
cin>>n>>m>>opx>>opy>>edx>>edy;
x.push(opx);
y.push(opy);
bfs();
}

跳马问题一(C++)

标签:space   out   c++   names   using   push   front   cout   exit   

原文地址:http://www.cnblogs.com/DZRDerek/p/6021055.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!