博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Guangsoushensou 2
阅读量:4467 次
发布时间:2019-06-08

本文共 2248 字,大约阅读时间需要 7 分钟。

/*C - 广搜 基础Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64uSubmit StatusDescriptionA friend of you is doing research on the Traveling Knight Problem (TKP) where you are to find the shortest closed tour of knight moves that visits each square of a given set of n squares on a chessboard exactly once. He thinks that the most difficult part of the problem is determining the smallest number of knight moves between two given squares and that, once you have accomplished this, finding the tour would be easy. Of course you know that it is vice versa. So you offer him to write a program that solves the "difficult" part. Your job is to write a program that takes two squares a and b as input and then determines the number of knight moves on a shortest route from a to b.InputThe input will contain one or more test cases. Each test case consists of one line containing two squares separated by one space. A square is a string consisting of a letter (a-h) representing the column and a digit (1-8) representing the row on the chessboard.OutputFor each test case, print one line saying "To get from xx to yy takes n knight moves.".Sample Inpute2 e4a1 b2b2 c3a1 h8a1 h7h8 a1b1 c3f6 f6Sample OutputTo get from e2 to e4 takes 2 knight moves.To get from a1 to b2 takes 4 knight moves.To get from b2 to c3 takes 2 knight moves.To get from a1 to h8 takes 6 knight moves.To get from a1 to h7 takes 5 knight moves.To get from h8 to a1 takes 6 knight moves.To get from b1 to c3 takes 1 knight moves.To get from f6 to f6 takes 0 knight moves.By Grant Yuan2014.7.12*/#include
#include
#include
#include
#include
using namespace std;bool flag[21][21];char a[21][21];int n,m;int s1,f1;typedef struct{ int x; int y;}node;int next[4][2]={1,0,0,1,-1,0,0,-1};int sum;node q[10000];int top,base;bool can(int cc,int dd){ if(cc>=0&&cc
=0&&dd
=base){ // c=q.front().x;d=q.front().y; c=q[base].x; d=q[base].y; for(int i=0;i<4;i++) { cc=c+next[i][0]; dd=d+next[i][1]; if(can(cc,dd)) { q1.x=cc; q1.y=dd; // cout<
<<" "<
<
>n>>m; if(n==0&&m==0) break; for(int i=0;i

版权声明:本文博主原创文章,博客,未经同意不得转载。

转载于:https://www.cnblogs.com/hrhguanli/p/4907710.html

你可能感兴趣的文章
多线程与静态代理
查看>>
php跳转网络连接
查看>>
设置链接的样式
查看>>
大数据环境安装部署步骤
查看>>
MySQL处理约束的方式
查看>>
Git & GitHub
查看>>
codeforces B. Shower Line 解题报告
查看>>
c# winform 关于DataGridView的一些操作(很全,绝对够用)
查看>>
数值数据与字符串数据
查看>>
接口测试的一个正常取值的实例
查看>>
SaltStack--使用salt-ssh
查看>>
华为任正非:不要瞧不起OV 好好学习人家
查看>>
JiuDuOj——1020
查看>>
__super:: 使用
查看>>
HTTP 方法:Get与Post分析
查看>>
HTML5落叶效果
查看>>
【计算机算法设计与分析】——4.4最优归并模式
查看>>
UESTC 1426 Boring Ranking
查看>>
android 修改framework下资源文件后如何编译
查看>>
【模板】左偏树
查看>>