【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

bfs模板题

【代码】

/*
1.Shoud it use long long ?
2.Have you ever test several sample(at least therr) yourself?
3.Can you promise that the solution is right? At least,the main ideal
4.use the puts("") or putchar() or printf and such things?
5.init the used array or any value?
6.use error MAX_VALUE?
7.use scanf instead of cin/cout?
*/
#include <bits/stdc++.h>
using namespace std;
#define y1 stupid_gcc
#define x1 stupid_gcc2 const int N = 8; string s1,s2;
int x1,y1,x2,y2;
int dx[8] = {1,2,2,1,-1,-2,-2,-1};
int dy[8] = {-2,-1,1,2,-2,-1,1,2}; int bo[N+5][N+5];
queue <pair<int,int> > dl; int main(){
#ifdef LOCAL_DEFINE
freopen("F:\\c++source\\rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
while (cin >> s1 >> s2){
x1 = s1[1]-'0',y1 = s1[0]-'a'+1;
x2 = s2[1]-'0',y2 = s2[0]-'a'+1;
memset(bo,255,sizeof bo);
bo[x1][y1] = 0;
dl.push(make_pair(x1,y1));
while (!dl.empty()){
int x = dl.front().first,y = dl.front().second;
dl.pop();
for (int i = 0;i < 8;i++){
int x1 = x + dx[i],y1 = y + dy[i];
if (x1 >= 1 && x1 <= 8 && y1<= 8 && y1 >=1 && bo[x1][y1]==-1){
bo[x1][y1] = bo[x][y]+1;
dl.push(make_pair(x1,y1));
}
}
}
cout << "To get from "<<s1<<" to "<<s2<<" takes " <<bo[x2][y2] << " knight moves."<<endl;
}
return 0;
}

【习题 6-4 UVA-439】Knight Moves的更多相关文章

  1. UVA 439 Knight Moves(BFS)

    Knight Moves option=com_onlinejudge&Itemid=8&category=11&page=show_problem&problem=3 ...

  2. UVA 439 Knight Moves --DFS or BFS

    简单搜索,我这里用的是dfs,由于棋盘只有8x8这么大,于是想到dfs应该可以过,后来由于边界的问题,TLE了,改了边界才AC. 这道题的收获就是知道了有些时候dfs没有特定的边界的时候要自己设置一个 ...

  3. UVA 439 Knight Moves

      // 题意:输入标准国际象棋棋盘上的两个格子,求马最少需要多少步从起点跳到终点 BFS求最短路: bfs并维护距离状态cnt, vis记录是否访问过 #include<cstdio> ...

  4. uva 439 Knight Moves 骑士移动

    这道题曾经写过,bfs.用队列,不多说了,上代码: #include<stdio.h> #include<stdlib.h> #include<string.h> ...

  5. 【UVa】439 Knight Moves(dfs)

    题目 题目     分析 没有估价函数的IDA......     代码 #include <cstdio> #include <cstring> #include <a ...

  6. Knight Moves UVA - 439

    A friend of you is doing research on the Traveling Knight Problem (TKP) where you are to find the sh ...

  7. UVA Knight Moves

    题目例如以下: Knight Moves  A friend of you is doing research on the Traveling Knight Problem (TKP) where ...

  8. UVa 439骑士的移动(BFS)

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  9. Knight Moves

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...

随机推荐

  1. Bit、Byte、kb、KB、MB、KiB、MiB各表示什么意思?

    1.Byte.bit:bit表示:位,是计算机中最小的数据单位.每一位的状态只能是0或1Byte表示:字节,8个二进制位构成1个字节,即1 Byte = 8 bit .1个英文字母或者数字占用1个字节 ...

  2. 【Django】ORM操作#2

    目录 必知必会的13条查询方法 单表查询之神奇的双下划线 一对多 ForeignKey 多对多 ManyToManyField 在Python脚本中调用Django环境 Django终端打印SQL语句 ...

  3. wordcontent小结

    gitee地址: https://gitee.com/yzpdegit/test 问题描述: 计算一个文件中所包含的单词数,字符个数,行数 需求分析: WordCount的需求可以概括为:对程序设计语 ...

  4. jQuery 判断是否包含在数组中 jQuery.inArray()

    var arr = [ "mysql", "php", "css", "js" ];   $.inArray(" ...

  5. SQL脚本存在TABLE ACCESS FULL行为

    对于SQL的执行计划,一般尽量避免TABLE ACCESS FULL的出现,那怎样去定位,系统里面哪些SQL脚本存在TABLE ACCESS FULL行为,对于9i及以后版本,使用以下语句即可 sel ...

  6. Vijos——T1626 爱在心中

    https://vijos.org/p/1626 描述 “每个人都拥有一个梦,即使彼此不相同,能够与你分享,无论失败成功都会感动.爱因为在心中,平凡而不平庸,世界就像迷宫,却又让我们此刻相逢Our H ...

  7. js插件---JS表格组件BootstrapTable行内编辑解决方案x-editable

    js插件---JS表格组件BootstrapTable行内编辑解决方案x-editable 一.总结 一句话总结:bootstrap能够做为最火的框架,绝对不仅仅只有我看到的位置,它应该还有很多位置可 ...

  8. C#开发 —— 基础知识

    C# 用于开发可以运行在 .Net 平台上的应用程序,C# 本身只是一种语言,尽管它是用于生成面向 .Net 环境的代码,但它本身不是 .Net 的一部分 Console.WriteLine 命名空间 ...

  9. TYVJ P1153 间谍网络

    P1153 间谍网络 时间: 1000ms / 空间: 131072KiB / Java类名: Main 描述 由于外国间谍的大量渗入,国家安全正处于高度危机之中.如果A间谍手中掌握着关于B间谍的犯罪 ...

  10. PatentTips - Enhancing the usability of virtual machines

    BACKGROUND Virtualization technology enables a single host computer running a virtual machine monito ...