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

【题意】

在这里输入题意

【题解】

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. Huawei设备配置系统时钟

    系统时钟是设备上的系统时间戳.由于地域的不同,用户可以根据当地规定设置系统时钟.用户必须正确设置系统时钟以确保其与其他设备保持同步.华为设备出厂时默认采用了协调世界时(UTC),但是没有配置时区所有在 ...

  2. javaScript 三目运算符初探

    三目运算符 三目运算符,又称条件运算符,是计算机语言的重要组成部分.它是唯一有3个操作数的运算符,所以有时又称为三元运算符.一般来说,三目运算符的结合性是右结合的. 定义 对于条件表达式b ? x : ...

  3. box-shadow制作各种单边,多边阴影

    一.box-shadow问题探究 box-shadow 在MDN定义以及详解: box-shadow 以由逗号分隔的列表来描述一个或多个阴影效果.该属性让你可以对几乎所有元素的边框产生阴影.如果元素同 ...

  4. CentOS7的聚合链路

    1.环境介绍 [root@rhcc ~]# cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core) ENERAL.DEVICE: en ...

  5. 循环GridControl所有行

    ; i < gridView1.RowCount; i++) { DataRowView row = (DataRowView)gridView1.GetRow(i); } gridView1是 ...

  6. iOS 开发之IPad的设计与实现

    // // main.m // 6-ipad // #import <Foundation/Foundation.h> #import "Ipad.h" int mai ...

  7. server环境信息【C#代码获取】

    server环境信息[C#代码获取] public class ServicesMessage { [DllImport("kernel32", CharSet = CharSet ...

  8. Outlook中设置会议的提醒

    https://support.office.com/en-us/article/Set-or-remove-reminders-7a992377-ca93-4ddd-a711-851ef359792 ...

  9. Material Design控件使用学习 toolbar+drawerlayout+ Snackbar

    效果 1.,导包design包和appcompat-v7 ,设置Theme主题Style为NoActionbar 2.custom_toolbar.xml <?xml version=" ...

  10. javaweb二

    除了servlet规范,还有filter,listener.filter和servlet相似,但是在servlet之前执行,主要区别是有一个FilterChain接口可以执行拦截方法. import ...