// Traveling Knight Problem
#include "stdafx.h"
#include <string>
#include <string.h>
#include<iostream>
#include <queue>
using namespace std;
int a[8][8];//棋盘
int MAP[8][2] = { { 2, 1 }, { 2, -1 }, { -2, 1 }, { -2, -1 }, { 1, 2 }, { -1, 2 }, { -1, -2 }, { 1, -2 } };//8个方向
typedef struct
{
int x;
int y;
int moves;
} NodeStru;
NodeStru Start, End,temp;
void bfs(queue<NodeStru>knight)
{
int x, y;
while (!knight.empty())
{
temp = knight.front();
knight.pop();
if (temp.x == End.x&&temp.y == End.y)
break;
for (int i = 0; i < 8; i++)
{
x = temp.x + MAP[i][0];
y = temp.y + MAP[i][1];
if (x >= 0 && x <8 && y >= 0 && y <8 &&!a[x][y])
{
Start.x = x, Start.y = y;
Start.moves = temp.moves + 1;
knight.push(Start);
a[x][y] = 1;//走过了
}
}
}
}
int main()
{
queue<NodeStru>knight;
string s1, s2;
//char s1[2], s2[2];
while (cin>>s1>>s2)
{ if(s1==s2)// (strcmp(s1,s2) == 0)
{
cout << "To get from " << s1 << " to "<<s2 << " takes 0 knight moves." << endl;
}
else
{
memset(a, 0, sizeof(a));
Start.x = s1[0] - 'a';
Start.y = s1[1] - 49;
a[Start.x][Start.y] = 1;
Start.moves = 0;
End.x = s2[0] - 'a';
End.y = s2[1] - 49;
///////////////////////////////////////////////
//入列
knight.push(Start);
bfs(knight);
cout << "To get from " << s1 << " to " << s2 << " takes "<<temp.moves<<" knight moves." << endl; } while (!knight.empty())
{
knight.pop();
}//记得清空栈!
} }

基本是老师的代码。。我就加了四句。。。但过程也是很不容易的,因为对visual studio太不熟悉了,为什么那个#include "stdafx.h"一定要加在第一句呢,还有cin>>char;
最后ctrl + z 会出现错误呢? 还有strcmp 为什么在string 时会出错?

zju 1091的更多相关文章

  1. Raspberry Pi 3 FAQ --- connect automatically to 'mirrors.zju.edu.cn' when downloading and how to accelerate download

    modify the software source: The software source is a place where several free application for linux ...

  2. zju 1002

    // zju 1002 // #include "stdafx.h" #include <string> #include <iostream> using ...

  3. [swustoj 1091] 土豪我们做朋友吧

    土豪我们做朋友吧(1091) 问题描述: 人都有缺钱的时候,缺钱的时候要是有个朋友肯帮助你,那将是一件非常幸福的事情.有N个人(编号为1到N),一开始他们互相都不认识,后来发生了M件事情,事情分为2个 ...

  4. ural 1091. Tmutarakan Exams 和 codeforces 295 B. Greg and Graph

    ural 1091 题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1091 题意是从1到n的集合里选出k个数,使得这些数满足gcd大于1 ...

  5. 人生第一场组队赛---2014.8 zju monthly

    暑期集训中段就组了队,不过一直没机会打比赛 昨天kitkat突然发现了zju要搞月赛,我想了一下题目对于我这种渣实在是有点难,于是想到干脆打一次组队赛吧,跟队友商量了一下也同意了 12点---17点  ...

  6. [Swust OJ 1091]--土豪我们做朋友吧(并查集,最值维护)

    题目链接:http://acm.swust.edu.cn/problem/1091/ Time limit(ms): 1000 Memory limit(kb): 32768   人都有缺钱的时候,缺 ...

  7. ural 1091. Tmutarakan Exams(容斥原理)

    1091. Tmutarakan Exams Time limit: 1.0 secondMemory limit: 64 MB University of New Tmutarakan trains ...

  8. 51Nod 1091 线段的重叠(贪心+区间相关,板子题)

    1091 线段的重叠 基准时间限制:1 秒 空间限制:131072 KB 分值: 5         难度:1级算法题 X轴上有N条线段,每条线段包括1个起点和终点.线段的重叠是这样来算的,[10 2 ...

  9. PAT 乙级 1091 N-自守数 (15 分)

    1091 N-自守数 (15 分) 如果某个数 K 的平方乘以 N 以后,结果的末尾几位数等于 K,那么就称这个数为“N-自守数”.例如 3×92​2​​=25392,而 25392 的末尾两位正好是 ...

随机推荐

  1. CF 504E Misha and LCP on Tree(树链剖分+后缀数组)

    题目链接:http://codeforces.com/problemset/problem/504/E 题意:给出一棵树,每个结点上有一个字母.每个询问给出两个路径,问这两个路径的串的最长公共前缀. ...

  2. CodeForces 483B Friends and Presents

     Friends and Presents Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I ...

  3. Cheatsheet: 2013 08.14 ~ 08.19

    .NET Lucene.Net ultra fast search for MVC or WebForms site => made easy! C# State Machines HttpCl ...

  4. extern "C" __declspec(dllexport) __declspec(dllimport) 和 def

    原文:extern "C" __declspec(dllexport) __declspec(dllimport) 和 def 前面的extern "C"  _ ...

  5. COM/ATL 资料收集

    COM/ATL COM基础知识 COM技术分类

  6. 列联表(Crosstabs)

    四格表(2*2的列联表): Tmin为最小的频数:N为频数之和. 1 当 Tmin≥5,N≥40时, 用普通卡方检验公式;2 当1≦Tmin≦5, N≥40时, 用校正卡方检验公式;3 Tmin< ...

  7. ImageMagick远程命令执行工具检测工具

    ImageMagick这个漏洞昨天晚上就出来了,今天才有时间研究一下,今天自己也测试了一下 效果图: ======================= 用lua写了一个检测脚本 print (" ...

  8. Metasploit RPC服务共享

    1) 启动一个新的MSF RPC服务,-P参数后面指定连接到的RPC服务需要提供的口令,-U参数指定连接所需输入的用户名,使用-a 0.0.0.0将RPC服务绑定到所有的网络地址,否则服务默认只绑定到 ...

  9. [SAP ABAP开发技术总结]物料、生产、采购、销售长文本

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  10. 【VB6笔记-02】从Command中获取链接参数

    Public Sub GetParameters() Dim Para As String Para = Command$() gstrUserID = GetCommandPara(Para, ) ...