• <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 
            久久精品国产2020| 久久WWW免费人成一看片| 久久精品aⅴ无码中文字字幕不卡| 欧美性大战久久久久久| 99蜜桃臀久久久欧美精品网站| 老男人久久青草av高清| 久久久噜噜噜www成人网| 国产成人久久久精品二区三区| 亚洲午夜精品久久久久久app| 无码任你躁久久久久久老妇App| 久久久国产乱子伦精品作者| 精品久久人人妻人人做精品 | 人妻系列无码专区久久五月天| 久久久这里只有精品加勒比| 国产精品毛片久久久久久久| 2021国内久久精品| 久久精品国产99国产精品| 亚洲∧v久久久无码精品| 色天使久久综合网天天| 97久久精品人妻人人搡人人玩| 久久久久99精品成人片试看| 久久伊人精品青青草原日本| 1000部精品久久久久久久久| 久久国产劲爆AV内射—百度| 亚洲国产精品成人久久蜜臀| 99久久精品免费看国产免费| 久久精品九九亚洲精品| 久久精品国产亚洲αv忘忧草| 久久久久国产一区二区三区| 久久久久AV综合网成人| 热re99久久6国产精品免费| 午夜视频久久久久一区 | 久久久久亚洲AV无码专区体验| 久久影院午夜理论片无码| 国产成人精品久久亚洲| 国产毛片久久久久久国产毛片| 久久99国产精一区二区三区| 久久久久久九九99精品| 久久精品亚洲精品国产色婷| 色综合久久久久久久久五月| 久久久久亚洲av成人网人人软件|