//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. IOS开发-UI学习-沙盒机制&文件操作

    ž苹果为软件的运行提供了一个沙盒机制 每个沙盒含有3个文件夹:Documents, Library 和 tmp.因为应用的沙盒机制,应用只能在几个目录下读写文件 žDocuments:苹果建议将程序中 ...

  2. UVa 11059 最大乘积

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  3. Android与JNI(一) ---- Java调用C 静态调用

    第一.通过eclipse新建一个工程名为HelloJni的android工程,并编译. 第二.右键工程-->Android Tools --> Add Native Support,出现如 ...

  4. Statemen接口对象

    利用Statement接口实现数据表的更新和查询操作 -取得Statement接口对象:Statement createStatement(int resultSetType, int resultS ...

  5. EF 实体字段设置主键和自增

    [Key] //主键 [DatabaseGenerated(DatabaseGeneratedOption.Identity)] //设置自增 public int id { get; set; } ...

  6. bzoj2049

    2049: [Sdoi2008]Cave 洞穴勘测 Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 7579  Solved: 3548[Submit] ...

  7. vim设置注意记录

    set vb t_vb= setlocal buftype = "解决不能保存buff错误

  8. PHP实现验证码图片

    <?php header("Content-type: image/png"); session_start(); $authnum = ''; $str = 'abcdef ...

  9. 记一次DG搭建过程中备库ORA-00210,ORA-00202,ORA-27086错误

    ORA-00210: cannot open the specified control file ORA-00202: control file: '/u01/app/oracle/oradata/ ...

  10. PHP安全编程

    转自:http://www.nowamagic.net/librarys/veda/detail/2076   1.关闭register_globals,以提高安全性 2.在部署环境,不要让不相关的人 ...