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

【题意】

在这里输入题意

【题解】

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. Cisco交换机IOS配置介绍

    一.模式• 用户模式(>):• 特权模式(#):• 全局配置模式(config#):• 接口配置模式(config-if#):• 线路模式(#config-line): 二.基本IOS命令结构• ...

  2. WebAssembly学习(一):认识WebAssembly

    WebAssembly作为一门新兴起的技术,在 JavaScript 圈非常的火!人们都在谈论它多么多么快,怎样怎样改变 Web 开发领域,被各大巨头所推广,这篇文章对其做一个简单的了解认识,本文非原 ...

  3. 本地运行github上的vue2.0仿饿了么webapp项目

    在vue刚刚开始流行的时候,大多数人学习大概都见到过这样的一个项目吧,可以作为学习此框架的一个模板了 github源码地址:https://github.com/RegToss/Vue-SPA 课程教 ...

  4. 【转】python的zipfile压缩、解压缩

    网上搜索了很多关于python的zipfile压缩.解压缩.觉得讲述比较详细,例子也很明了.由于比较懒,就直接复制了. 以下内容大部分转于 http://blog.csdn.net/jgood/art ...

  5. 【CS Round #37 (Div. 2 only) A】Boring Number

    [Link]:https://csacademy.com/contest/round-37/task/boring-number/ [Description] 让你找离平均数最近的一个数的下标; [S ...

  6. GridControl添加右键菜单

    private void gridView1_MouseDown(object sender, MouseEventArgs e) { GridHitInfo vi = gridView1.CalcH ...

  7. 用c#编写爬虫在marinetraffic下载船仅仅图片

    近期在做船仅仅识别方面的事情,须要大量的正样本来训练adaboost分类器. 于是到marinetraffic这个站点上下载船仅仅图片.写个爬虫来自己主动下载显然非常方便. 站点特点 在介绍爬虫之前首 ...

  8. JavaFX 一 出生新手村(阅读小规则)

    我就不讲IDE怎么装的,网上有的是,我仅仅是说说我学习过程中遇到的,该注意的东西 1.JavaFX刚開始出是基于脚本script开发的语言,所以网上会有流传比較多关于script的JavaFX,对于被 ...

  9. PHP CLI模式下的多进程应用分析

    PHP在非常多时候不适合做常驻的SHELL进程, 他没有专门的gc例程, 也没有有效的内存管理途径. 所以假设用PHP做常驻SHELL, 你会常常被内存耗尽导致abort而unhappy 并且, 假设 ...

  10. python-安装xlrd xlwt 插件

    最近需要对比两个表格的内容,然后修改其中的某列内容.因为工作量太大,所以想通过python来实现.上网查了相关的操作,其中牵扯到两个功能模块,xlrd xlwt.这两个功能模块分别是对excel进行读 ...