• <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 
            91精品国产91久久久久福利| 97精品伊人久久久大香线蕉| www久久久天天com| 国产精品福利一区二区久久| 91精品日韩人妻无码久久不卡| 久久久久亚洲AV成人网| 久久人人爽人人人人片av| av无码久久久久久不卡网站| 香港aa三级久久三级老师2021国产三级精品三级在 | 亚洲成色www久久网站夜月| A狠狠久久蜜臀婷色中文网| 久久国产福利免费| 久久精品国产亚洲77777| 久久性精品| 国产精品一久久香蕉产线看| 欧美激情一区二区久久久| 久久精品这里热有精品| 97精品伊人久久久大香线蕉| 久久久久久久国产免费看| 久久久亚洲欧洲日产国码二区| 四虎国产精品免费久久| 99久久免费国产精品热| 2021国内精品久久久久久影院| 国产高清美女一级a毛片久久w| 亚洲国产另类久久久精品黑人| 久久99精品久久久久久齐齐| 久久精品国产久精国产| 久久综合九色综合网站| 中文精品久久久久人妻不卡| 无码精品久久一区二区三区 | 久久这里只有精品首页| 久久97久久97精品免视看| 一级做a爰片久久毛片16| 国产Av激情久久无码天堂| 久久久久se色偷偷亚洲精品av| 日本高清无卡码一区二区久久| 精品多毛少妇人妻AV免费久久| 热久久这里只有精品| 久久亚洲精品视频| 91亚洲国产成人久久精品网址| 97久久超碰国产精品2021|