• <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 
            欧美亚洲另类久久综合| 婷婷综合久久狠狠色99h| 亚洲国产成人乱码精品女人久久久不卡| 亚洲精品国产成人99久久| 亚洲人成无码网站久久99热国产| 久久亚洲精品无码VA大香大香| 久久中文字幕人妻熟av女| 99久久精品国产高清一区二区| 久久精品国产亚洲AV不卡| 97久久婷婷五月综合色d啪蜜芽| 久久99精品久久久久久久久久| 久久久久国产精品嫩草影院 | 久久久久高潮毛片免费全部播放| 亚洲国产精品久久久久网站| 一本色道久久综合亚洲精品| 国产高清美女一级a毛片久久w | 99久久精品国内| 一级女性全黄久久生活片免费| 色综合久久综合网观看| 色综合久久久久综合体桃花网| 国内精品久久久久久中文字幕| 精品久久无码中文字幕| 亚洲中文字幕无码久久精品1| 久久亚洲精品无码观看不卡| 久久99精品国产一区二区三区| 精品国产乱码久久久久久人妻| 久久亚洲av无码精品浪潮| 品成人欧美大片久久国产欧美...| 无码人妻久久一区二区三区| 无码任你躁久久久久久| 久久亚洲av无码精品浪潮| 久久播电影网| 色婷婷综合久久久久中文字幕 | 久久久久人妻精品一区| 国产99久久久国产精品小说| 久久亚洲国产精品123区| 日韩中文久久| 欧美噜噜久久久XXX| 久久久久久午夜成人影院| 国内精品久久久久久99蜜桃| 72种姿势欧美久久久久大黄蕉|