//P177 test 6-4 UVa439
 #include<cstdio>
 #include<cstring>
 #include<queue>
 using namespace std;

 , , , , -, -, -, -};            //转向控制
 , -, , -, , -, , -};

 ][];                                        //记录步数 

 void bfs(int x,int y,int ex,int ey)
 {
     queue<int> a, b;
     a.push(x);
     b.push(y);
     int px, py;
     ;

     while(!a.empty())
     {
         px = a.front();
         a.pop();
         py = b.front();
         b.pop();

         ; i < ; i++)
         {
              && px + turnx[i] <=  && py + turny[i] >  && py + turny[i] <= )
             {
                 step[px + turnx[i]][py + turny[i]] = step[px][py] + ;
                 b.push(py + turny[i]);
                 a.push(px + turnx[i]);

                 if(px + turnx[i] == ex && py + turny[i] == ey)
                 {
                     kase = ;
                     break;
                 }
             }
         }

         if(kase)break;
     }
 }
 int main()
 {
     int x, ex, y, ey;
     ],s2[];
     )
     {
         x = s1[] - ;
         y = s1[] - ' ;
         ex = s2[] - ;
         ey = s2[] - ' ;
         memset(step, , sizeof(step));
         bfs(x,y,ex,ey);
         printf("%d\n", step[ex][ey]);
     }

     ;
 }

P177 test 6-4 UVa439的更多相关文章

  1. P177 test 6-3 UVa536

    //P177 test 6-3 #include<cstdio> #include<cstring> using namespace std; +],s2[+]; int re ...

  2. [刷题]算法竞赛入门经典(第2版) 6-4/UVa439 6-5/UVa1600

    比较忙比较累,只贴代码了. 题目:6-4 UVa439 - Knight Moves //UVa439 - Knight Moves //Accepted 0.000s //#define _XIEN ...

  3. uva-439

    题意:骑士在一个8*8的棋盘上移动,1-8代表行号,a-h代表列号,给出骑士的初始位置和目的位置,求骑士最少的移动步数:题目隐含一层意思(骑士移动规则是中国象棋的“马”的走法) 输入:一串字符串,包含 ...

  4. uva439 - Knight Moves(BFS求最短路)

    题意:8*8国际象棋棋盘,求马从起点到终点的最少步数. 编写时犯的错误:1.结构体内没构造.2.bfs函数里返回条件误写成起点.3.主函数里取行标时未注意书中的图. #include<iostr ...

  5. UVa439——骑士的移动

    简单bfs #include <iostream> #include <cstring> #include <string> #include <map> ...

  6. Uva439:BFS题目总结

    #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <cstring> #include <cstd ...

  7. UVA439 knightMoves (A*启发搜索)

    第一个A*,纪念下. A*要保证最短路一定要估价函数小于等于实际值,越接近越好 估价函数取Manhattan距离除以二. //Rey #include<cstdio> #include&l ...

  8. 【习题 6-4 UVA-439】Knight Moves

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] bfs模板题 [代码] /* 1.Shoud it use long long ? 2.Have you ever test sev ...

  9. UVA439 骑士的移动 Knight Moves

    #include<bits/stdc++.h> using namespace std; char a,c; int b,d; ][]; ]={,,,-,,-,-,-}; ]={,-,,, ...

随机推荐

  1. C语言-if语句

    1.一般形式 if(表达式)表达式1 else 表达式2   :表达式成立(为真)则执行表达式1,否则执行表达式2. 适用范围:真假,对错,开关,对立面的条件 注意:如果if语句中只包括一条语句,可以 ...

  2. redhat在线安装chrome浏览器

    开始的时候是参考吹尽黄沙始到金的文章http://www.cnblogs.com/effective/archive/2012/03/18/2405189.html 1.创建一个文件/etc/yum. ...

  3. java设计模式笔记(1)-适配器模式

    适配器的定义 适配器就是一个接口转换器,它可以是一个独立的硬件接口设备,允许硬件或电子接口与其它硬件或电子接口相连,也可以是信息接口.比如:电源适配器.三角架基座转接部件.USB与串口的转接设备等. ...

  4. pyv8安装

    http://www.thinksaas.cn/topics/0/400/400915.html

  5. 创建 Web 前端开发环境(node和npm以及git)

    Web 前端开发涉及多种工具,这里将常用工具的安装和配置进行说明,提供了详细的说明,为后继的开发创建一个坚实的基础. 本文介绍的工具有:NodeJS, NPM, Bower, Git 和 Grunt. ...

  6. PHP导出MYSQL数据库并压缩

    PHP可以一键导出MYSQL备份文件,并压缩存放,尽管phpMyAdmin有这功能,不过若你自己开发网站或者是为别人写CMS,你不应该要求别人用你程序的时候再去另外用phpMyAdmin备份MYSQL ...

  7. fold change(ratio)

    fold change 英文简称 : FC 中文全称 : 倍性变化 所属分类 : 生物科学 词条简介 : 一种用于描述两个用于相比的对象数量差异的方法.例如,第一个样本和第二个样本的量是50/10,那 ...

  8. CSS文字大小单位PX、EM、PT

    老是被人问到px.pt和em的区别,自己有时候也会纠结到底该用什么单位,今天特意查了一些文章,下面这篇虽然很久远了,但解释的比较全面,转载收藏之.点击查看原文 这里引用的是Jorux的"95 ...

  9. 写过的一些shell脚本总结

    每天晚上自动检查更新 #!/bin/sh #auto gamedown2 version DATE=`/bin/date +%m%d` COUNT=`curl 'http://11.1.1.1/ind ...

  10. 判断js对象的数据类型,有没有一个最完美的方法?

    先来一个例子: var string1=""; var string2=new String(""); alert(typeof string1); // st ...