• <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>

            輸入一個棋盤 ( p × q ),從任意點開始,每次走日子格,求能走遍每個點的序列,以Sample中給出的樣式按字典序輸出,如果得不到這樣的序列輸出impossible

            由于要按字典序輸出,所以優先訪問坐標較小的點,第一次得到的序列就是所求結果

            #include <iostream>
            #include <cstdio>
            #include <cstring>
            #include <vector>
             
            using namespace std;
             
            int const maxn = 30;
             
            bool vis[maxn][maxn];
            int p, q;
            bool flag = false;
             
            int const steps[8][2= { { -1-2 }, { 1-2 }, { -2-1 }, { 2-1 }, { -21 }, { 21 }, { -12 }, { 12 } };
             
            typedef struct node
            {
                int x;
                int y;
            }coordinate;
             
            bool judge()
            {
                forint i = 0; i < p; i++ )
                    forint j = 0; j < q; j++ )
                        if!vis[i][j] )
                            return false;
                return true;
            }
             
            vector<coordinate> path;
             
            void dfs( int x, int y )
            {
                if( flag )
                    return;
                if( judge() && !flag ) {
                    printf( "A1" );
                    forint i = 0; i < path.size(); i++ ){
                        printf( "%c", path[i].y + 65 );
                        printf( "%d", path[i].x + 1 );
                    }
                    puts("");
                    flag = true;
                    return;
                }
                forint i = 0; i < 8; i++ ) {
                    int next_x = x + steps[i][0];
                    int next_y = y + steps[i][1];
                    if( next_x >= 0 && next_x < p && next_y >= 0 && next_y < q && !vis[next_x][next_y] ) {
                        coordinate tmp;
                        tmp.x = next_x;
                        tmp.y = next_y;
             
                        path.push_back( tmp );
                        vis[next_x][next_y] = 1;
             
                        dfs( next_x, next_y );
             
                        vis[next_x][next_y] = 0;
                        path.pop_back();
                    }
                }
             }
             
            int main()
            {
                int n; scanf( "%d"&n );
             
                forint i = 0; i < n; i++ ) {
                    scanf( "%d%d"&p, &q );
             
                    flag = false;
             
                    printf( "Scenario #%d:\n", i + 1 );
             
                    memset( vis, 0sizeof( vis ) );
             
                    path.clear();
                    vis[0][0= 1;
                    dfs( 00 );
                    if!flag )
                        printf( "impossible\n" );
                    puts("");
             
                }
                return 0;
            }
            posted on 2016-08-31 10:16 Vontroy 閱讀(201) 評論(0)  編輯 收藏 引用
            久久久久国产亚洲AV麻豆| 色综合久久无码五十路人妻| 久久久久久亚洲精品不卡| 精品久久久一二三区| 久久精品国产99久久无毒不卡| 人人狠狠综合久久亚洲88| 久久婷婷五月综合97色直播| 99久久99久久精品国产| 亚洲国产另类久久久精品小说 | 精品久久久久中文字幕一区| 久久AV高潮AV无码AV| 久久久91人妻无码精品蜜桃HD| 久久久婷婷五月亚洲97号色| 伊人色综合久久天天人守人婷 | 亚洲国产精品人久久| 亚洲中文字幕无码一久久区| 91亚洲国产成人久久精品| 香蕉久久av一区二区三区| 国产精品中文久久久久久久| 大美女久久久久久j久久| 99久久婷婷免费国产综合精品| 一本综合久久国产二区| 人妻精品久久久久中文字幕| 成人a毛片久久免费播放| 精品综合久久久久久97超人 | 久久精品一本到99热免费| 久久嫩草影院免费看夜色| 久久精品麻豆日日躁夜夜躁| 久久亚洲精品无码aⅴ大香| 国产福利电影一区二区三区久久老子无码午夜伦不 | 国产精品亚洲美女久久久| 久久久久久九九99精品| 亚洲精品国产字幕久久不卡| 久久久久亚洲国产| 久久久久国色AV免费观看| 91精品日韩人妻无码久久不卡| 日本福利片国产午夜久久| 激情久久久久久久久久| 日本精品久久久久久久久免费| 亚洲午夜无码久久久久小说| 思思久久精品在热线热|