• <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 
            99久久www免费人成精品| 久久夜色精品国产噜噜亚洲a| 无码人妻久久一区二区三区蜜桃 | 国产精品99久久精品| 国产69精品久久久久99尤物| 精品久久久久久无码中文字幕| 色婷婷久久久SWAG精品| 久久妇女高潮几次MBA| 精品久久久无码中文字幕天天| 伊人久久大香线蕉综合5g| 成人妇女免费播放久久久| 国产成人无码精品久久久免费 | 理论片午午伦夜理片久久| 亚洲精品高清一二区久久| 72种姿势欧美久久久久大黄蕉| 欧美日韩精品久久久久| 9久久9久久精品| 久久精品桃花综合| 久久人搡人人玩人妻精品首页| 欧美牲交A欧牲交aⅴ久久| 亚洲精品久久久www| 成人a毛片久久免费播放| 人妻精品久久无码专区精东影业| 久久精品成人免费观看97| 亚洲国产成人久久精品影视 | 久久精品无码一区二区app| 久久亚洲私人国产精品| 九九久久精品无码专区| 丁香五月综合久久激情| 国产精品久久久久久久久| 久久久噜噜噜久久中文福利| 久久久久免费精品国产| 午夜精品久久久久| 久久99热这里只有精品66| 欧美麻豆久久久久久中文| 久久人人爽人人澡人人高潮AV | 久久久久久人妻无码| 国产亚洲美女精品久久久2020| 亚洲国产日韩欧美久久| 要久久爱在线免费观看| 人妻无码αv中文字幕久久琪琪布|