• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            superman

            聚精會神搞建設 一心一意謀發展
            posts - 190, comments - 17, trackbacks - 0, articles - 0
               :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

            ZOJ 1091 - Knight Moves

            Posted on 2008-05-03 16:27 superman 閱讀(482) 評論(0)  編輯 收藏 引用 所屬分類: ZOJ
             1 /* Accepted 1091 C++ 00:00.08 844K */
             2 #include <queue>
             3 #include <iostream>
             4 
             5 using namespace std;
             6 
             7 struct rec { int x, y, cnt; };
             8 struct { int x, y; } dir[8= {
             9     {-2+1}, {-1+2}, {+1+2}, {+2+1},
            10     {+2-1}, {+1-2}, {-1-2}, {-2-1}
            11 };
            12 
            13 inline bool inside(const int x, const int y)
            14 {
            15     if(x >= 0 && x < 8 && y >= 0 && y < 8)
            16         return true;
            17     return false;
            18 }
            19 
            20 int BFS(int sx, int sy, int tx, int ty)
            21 {
            22     bool visited[8][8= {false};
            23     
            24     visited[sx][sy] = true;
            25     rec cur = {sx, sy, 0};
            26     queue <rec> q;
            27     q.push(cur);
            28     
            29     while(q.empty() == false)
            30     {
            31         cur = q.front(); q.pop();
            32         
            33         if(cur.x == tx && cur.y == ty)
            34             return cur.cnt;
            35         
            36         for(int i = 0; i < 8; i++)
            37         {
            38             int x = cur.x + dir[i].x;
            39             int y = cur.y + dir[i].y;
            40             
            41             if(inside(x, y) && visited[x][y] == false)
            42             {
            43                 visited[x][y] = true;
            44                 rec tmp = {x, y, cur.cnt + 1};
            45                 q.push(tmp);
            46             }
            47         }
            48     }
            49 }
            50 
            51 int main()
            52 {
            53     char sx, sy, tx, ty;
            54     while(cin >> sx >> sy >> tx >> ty)
            55     {
            56         sx -= 'a', sy = sy - '0' - 1;
            57         tx -= 'a', ty = ty - '0' - 1;
            58         printf("To get from %c%d to %c%d takes %d knight moves.\n",
            59             sx + 'a', sy + 1, tx + 'a', ty + 1, BFS(sx, sy, tx, ty));
            60     }
            61     
            62     return 0;
            63 }
            64 
            91久久精品电影| 久久精品国产亚洲AV无码偷窥| 狠狠色丁香久久综合五月| 久久久久久午夜成人影院| 91精品国产综合久久四虎久久无码一级 | 久久精品成人免费观看97| 欧美成a人片免费看久久| 久久精品国产免费观看三人同眠| 久久久噜噜噜久久熟女AA片| 中文字幕一区二区三区久久网站| 青青草原综合久久大伊人导航| 天天躁日日躁狠狠久久| 亚洲狠狠久久综合一区77777| 一级女性全黄久久生活片免费| 久久午夜无码鲁丝片| 亚洲国产香蕉人人爽成AV片久久| 久久亚洲精精品中文字幕| 91久久精品电影| 久久精品国产亚洲av麻豆小说 | 一本伊大人香蕉久久网手机| 国产精品久久久香蕉| 伊人热人久久中文字幕| 久久综合给合久久国产免费| 亚洲精品视频久久久| 久久精品国产只有精品66| 青青国产成人久久91网| 亚洲午夜无码久久久久| 香蕉久久影院| 久久精品国产色蜜蜜麻豆| 青青国产成人久久91网| 2021久久国自产拍精品| 久久久一本精品99久久精品88| 亚洲天堂久久久| 久久精品桃花综合| 久久毛片一区二区| 狠狠色丁香久久婷婷综合蜜芽五月| 久久e热在这里只有国产中文精品99 | 69久久精品无码一区二区| 国产精品久久久亚洲| 粉嫩小泬无遮挡久久久久久| 久久亚洲AV成人无码国产|