• <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 閱讀(477) 評論(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 
            无码国内精品久久人妻蜜桃| 国产精品美女久久久久久2018| 国产99久久久国产精免费| 色综合久久天天综合| 久久精品国产亚洲AV不卡| 麻豆国内精品久久久久久| 久久久黄色大片| 久久国产色AV免费观看| 青青草原综合久久大伊人精品| 久久男人AV资源网站| 久久99热这里只频精品6| 伊人久久大香线蕉综合Av| 国产91色综合久久免费分享| 久久久精品国产亚洲成人满18免费网站 | 99久久国产综合精品网成人影院 | 久久精品国产精品青草app| 精品免费久久久久国产一区| 97久久国产露脸精品国产| 99久久精品费精品国产| 亚洲va久久久噜噜噜久久天堂| 久久精品免费观看| 九九精品久久久久久噜噜| 久久久精品人妻一区二区三区蜜桃| 久久亚洲国产精品123区| 久久久一本精品99久久精品88| 久久九色综合九色99伊人| 久久国产精品一国产精品金尊| 亚洲欧洲久久av| 久久久久久国产精品美女| 久久99精品国产麻豆| 欧美亚洲国产精品久久| 精品国产综合区久久久久久 | 久久中文娱乐网| 久久AV高清无码| 一本久久a久久精品亚洲| 无码八A片人妻少妇久久| 亚洲欧美成人久久综合中文网| 国产真实乱对白精彩久久| 精品久久国产一区二区三区香蕉 | 久久中文字幕人妻丝袜| 亚洲国产成人乱码精品女人久久久不卡|