基础BFS,水过就好~手写队列优化~~

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f
const double pi = acos(-1.0);
const int mod =9973; const int N =1e1+10; struct asd{
int x,y;
int step;
};
asd no,ne;
asd q[N*N];
int sx,sy,ex,ey;
int dx[8]={-1,-1,-2,-2,1,1,2,2};
int dy[8]={2,-2,1,-1,-2,2,-1,1};
bool vis[N][N]; int BFS()
{
memset(vis,0,sizeof(vis));
int head,tail;
head=0;
tail=1;
q[head].x=sx;
q[head].y=sy;
vis[sx][sy]=1;
while(head<tail)
{
int ax=q[head].x;
int ay=q[head].y;
if(ax==ex&&ay==ey)
return q[head].step;
for(int i=0;i<8;i++)
{
int aa=dx[i]+ax;
int bb=dy[i]+ay;
if(aa<0||aa>7||bb<0||bb>7||vis[aa][bb])
continue;
vis[aa][bb]=1;
q[tail].x=aa;
q[tail].y=bb;
q[tail].step=q[head].step+1;
tail++;
}
head++;
}
} int main()
{
char a[5],b[5];
while(~scanf("%s%s",a,b))
{
memset(vis,0,sizeof(vis));
sx=a[0]-'a';
sy=a[1]-'0'-1;
ex=b[0]-'a';
ey=b[1]-'0'-1;
int qq;
qq=BFS();
printf("To get from %s to %s takes %d knight moves.\n",a,b,qq);
}
return 0;
}

跳马~~~HDU1372的更多相关文章

  1. [itint5]跳马问题加强版

    http://www.itint5.com/oj/#12 首先由跳马问题一,就是普通的日字型跳法,那么在无限棋盘上,任何点都是可达的.证法是先推出可以由(0,0)到(0,1),那么由对称型等可知任何点 ...

  2. HDU1372:Knight Moves(经典BFS题)

    HDU1372:Knight Moves(BFS)   Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %l ...

  3. [BZOJ 4417][Shoi2013]超级跳马

    4417: [Shoi2013]超级跳马 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 379  Solved: 230[Submit][Status ...

  4. 洛谷 P3990 [SHOI2013]超级跳马 解题报告

    P3990 [SHOI2013]超级跳马 题目描述 现有一个\(n\) 行 \(m\) 列的棋盘,一只马欲从棋盘的左上角跳到右下角.每一步它向右跳奇数列,且跳到本行或相邻行.跳越期间,马不能离开棋盘. ...

  5. 骑士周游问题跳马问题C#实现(附带WPF工程代码)

    骑士周游问题,也叫跳马问题. 问题描述: 将马随机放在国际象棋的8×8棋盘的某个方格中,马按走棋规则进行移动.要求每个方格只进入一次,走遍棋盘上全部64个方格. 代码要求: 1,可以任意选定马在棋盘上 ...

  6. cogs——49. 跳马问题

    49. 跳马问题 水题 dfs裸基础 #include<cstdio> using namespace std; ]={,,,,}, ans,my[]={,-,,-,}; inline v ...

  7. code vs 1216 跳马问题

    1216 跳马问题  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description 题目 输入描述 Input Descri ...

  8. cogs 49. 跳马问题

    49. 跳马问题 ★   输入文件:horse.in   输出文件:horse.out   简单对比时间限制:1 s   内存限制:128 MB [问题描述] 有一只中国象棋中的 “ 马 ” ,在半张 ...

  9. poj2243 &amp;&amp; hdu1372 Knight Moves(BFS)

    转载请注明出处:viewmode=contents">http://blog.csdn.net/u012860063?viewmode=contents 题目链接: POJ:http: ...

随机推荐

  1. mysql 安装与启动

    1.下载mysql installer 2.安装 一直点next,直到finish. 3.安装时的配置 安装完后,选择立即开始配置. 选择standard configuration 勾选安装mysq ...

  2. 常用linux系统监控命令

    一.内存监控 监控内存的使用状态是非常重要的,通过监控有助于了解内存的使用状态,比如内存占用是否正常,内存是否紧缺等等,监控内存最常使用的命令有free.vmstat.top等 1.1 free $ ...

  3. IOS7 开发注意事项

    1,修改状态栏的样式和隐藏. 首先,需要在Info.plist配置文件中,增加键:UIViewControllerBasedStatusBarAppearance,并设置为YES: 然后,在UIVie ...

  4. vue 安装与起步

    vue安装: 1.官网下载vue,在script标签里引用(去下载) 2.使用CDN(建议下载到本地,不推荐这种方法): BootCDN:https://cdn.bootcss.com/vue/2.2 ...

  5. HDOJ1002

    #include <iostream>#include<stdio.h> using namespace std;int main(){ int T, count_T; cha ...

  6. querying rpm database

    Call dbMatch on a transaction set to create a match iterator. As with the C API, a match iterator al ...

  7. all rows from client_id can grow infinitely compared to a single node when hashing by client_id

    all rows from client_id can grow infinitely compared to a single node when hashing by client_id Re: ...

  8. compile java sources

    Information:javac 1.8.0_91 was used to compile java sources D:\myjdk\bin\java "-javaagent:C:\Pr ...

  9. node-sass 安装失败win32-x64-48_binding.node

    升级了nodejs的版本,原项目的node-sass模块启动安装不了. 下载对应的win32-x64-xx_binding.node https://github.com/sass/node-sass ...

  10. C# 给窗体添加事件

    1.https://zhidao.baidu.com/question/588485101.html