//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. PHP利用数组构造JSON

    问题起因 以往都是直接用构造数组的形式构造json 例子: $arr = array("A"=>"1","B"=>"2 ...

  2. 企业建站http://www.douco.com/

    http://www.douco.com/ 非常方便的,搭建简单的企业网站

  3. MongoDB的$type操作符

    字段类型定义: db.col.find({"title" : {$type : 2}})

  4. spring.net的基本搭建

    这几天在学C#,感觉还是需要一个控制反转的框架,正好Spirng也有.net版的,看着API搭建一个 大致目录是这样的,我们在APP.CONFIG里面配好xml文件的地址,这个APP.CONFIG就相 ...

  5. css3 翻牌效果

    <!DOCTYPE html> <head> <meta http-equiv="Content-Type" content="text/h ...

  6. Linux服务器开发/测试环境搭建-流程

    1.MariaDB yum 安装/初始化/授远程权限 yum安装 在MariaDB官网根据Linux系统查找您所需要的db版本:https://downloads.mariadb.org/mariad ...

  7. PHP使用JPG生成GIF动画图片,基于php_imagick_st-Q8.dll

    PHP使用php_imagick_st-Q8.dll类库,把JPG图片连接生成GIF动画图片,需要事先下载好php_imagick_st-Q8.dll,文件,并配置php.ini文件,启用php_im ...

  8. redis 安装启动及设置密码<windows>

    redis 1. 安装 1.1 下载解压包,直接解压到任意路径下即可 windows下载地址:ttps://github.com/MSOpenTech/redis/releases 2.启动 2.1 ...

  9. 破解&屏蔽防止嵌入框架代码 top.location != self.location

    <script type="text/javascript"> if (top.location != self.location) top.location = se ...

  10. iconfont.cn阿里巴巴矢量图下载字体图标实战

    1.阿里巴巴矢量图网址:www.iconfont.cn 2.然后用新浪微博账号登录 3.输入要查找的图标相应的关键字,回车 4.滑过要找的图标,点击购物车,让图标存储到暂存架中 5.点击暂存架,存储为 ...