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

            poj2488

            A Knight's Journey

            Time Limit: 1000MS Memory Limit: 65536K
            Total Submissions: 18085 Accepted: 6095

            Description

            Background
            The knight is getting bored of seeing the same black and white squares again and again and has decided to make a journey
            around the world. Whenever a knight moves, it is two squares in one direction and one square perpendicular to this. The world of a knight is the chessboard he is living on. Our knight lives on a chessboard that has a smaller area than a regular 8 * 8 board, but it is still rectangular. Can you help this adventurous knight to make travel plans?

            Problem
            Find a path such that the knight visits every square once. The knight can start and end on any square of the board.

            Input

            The input begins with a positive integer n in the first line. The following lines contain n test cases. Each test case consists of a single line with two positive integers p and q, such that 1 <= p * q <= 26. This represents a p * q chessboard, where p describes how many different square numbers 1, . . . , p exist, q describes how many different square letters exist. These are the first q letters of the Latin alphabet: A, . . .

            Output

            The output for every scenario begins with a line containing "Scenario #i:", where i is the number of the scenario starting at 1. Then print a single line containing the lexicographically first path that visits all squares of the chessboard with knight moves followed by an empty line. The path should be given on a single line by concatenating the names of the visited squares. Each square name consists of a capital letter followed by a number.
            If no such path exist, you should output impossible on a single line.

            Sample Input

            3
            1 1
            2 3
            4 3

            Sample Output

            Scenario #1:
            A1
            
            Scenario #2:
            impossible
            
            Scenario #3:
            A1B3C1A2B4C2A3B1C3A4B2C4
            
            這個題目要求給出遍歷棋盤的字典序,所以要給擴展一個順序,我也不明白為什么這樣是字典序 








            dx[8][2]={{-2,-1},{-2,1},{-1,-2},{-1,2},{1,-2},{1,2},{2,-1},{2,1}};

            這個搜索順序總是先找字母數字小的,即以左上角為原點,當前為(i,j)總是找比先找比該點行或列小的,在找行或列大的,
            行列中總是先找行
            這里的行要按字母順序,列要按數字順序,樣例很糾結、




            如果是存在能遍歷棋盤上所有點的解的話,那從棋盤上任意一點出發總能遍歷棋盤上所有的點,、
            這里要
             1#include<stdio.h>
             2#include<string.h>
             3#include<math.h>
             4int dx[8][2]={{-2,-1},{-2,1},{-1,-2},{-1,2},{1,-2},{1,2},{2,-1},{2,1}};
             5int stack[100][2];
             6int n,m,tot;
             7int mark[27][27];
             8short flag;
             9void print()
            10{
            11    int i;
            12    for (i=1;i<=tot ;i++ )
            13    {
            14        printf("%c%d",stack[i][0]+64,stack[i][1]);
            15    }

            16    printf("\n");
            17}

            18void dfs(int num)
            19{
            20    int i,xn,yn,x,y,numn;
            21    if (num==tot&&!flag)
            22    {
            23        print();
            24        flag=1;
            25        return;
            26    }

            27    x=stack[num][0];
            28    y=stack[num][1];
            29    for (i=0;i<8 ;i++ )
            30    if (flag==0)
            31    {
            32        xn=x+dx[i][0];
            33        yn=y+dx[i][1];
            34        if ((xn>0)&&(xn<=n)&&(yn>0)&&(yn<=m)&&(mark[xn][yn]==0))
            35        {
            36            numn=num+1;
            37            mark[xn][yn]=1;
            38            stack[numn][0]=xn;stack[numn][1]=yn;
            39            dfs(numn);
            40            mark[xn][yn]=0;
            41        }

            42    }

            43    else return;
            44}

            45int main()
            46{
            47    int t,i;
            48    scanf("%d",&t);
            49    for (i=1;i<=t ;i++ )
            50    {
            51        scanf("%d%d",&m,&n);
            52        memset(mark,0,sizeof(mark));
            53        memset(stack,0,sizeof(stack));
            54        mark[1][1]=1;
            55        tot=n*m;
            56        flag=0;
            57        stack[1][0]=1;
            58        stack[1][1]=1;
            59        printf("Scenario #%d:\n",i);
            60        dfs(1);
            61        if (!flag)
            62        {
            63            printf("impossible\n");
            64        }

            65        //if (i!=t)
            66        {
            67            printf("\n");
            68        }

            69    }

            70    return 0;
            71}

            72
            求字典序
            所以應從(1,1)開始遍歷































            posted on 2012-02-28 13:19 jh818012 閱讀(1822) 評論(0)  編輯 收藏 引用

            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導航

            統計

            常用鏈接

            留言簿

            文章檔案(85)

            搜索

            最新評論

            • 1.?re: poj1426
            • 我嚓,,輝哥,,居然搜到你的題解了
            • --season
            • 2.?re: poj3083
            • @王私江
              (8+i)&3 相當于是 取余3的意思 因為 3 的 二進制是 000011 和(8+i)
            • --游客
            • 3.?re: poj3414[未登錄]
            • @王私江
              0ms
            • --jh818012
            • 4.?re: poj3414
            • 200+行,跑了多少ms呢?我的130+行哦,你菜啦,哈哈。
            • --王私江
            • 5.?re: poj1426
            • 評論內容較長,點擊標題查看
            • --王私江
            日韩中文久久| 亚洲va久久久噜噜噜久久狠狠| 久久久久成人精品无码中文字幕| 欧美丰满熟妇BBB久久久| 久久国产精品无码一区二区三区| 成人国内精品久久久久一区| 国产精品午夜久久| 亚洲人成伊人成综合网久久久| 97精品久久天干天天天按摩| 久久久黄片| 久久99国产精品二区不卡| 日日狠狠久久偷偷色综合96蜜桃| 精品久久久久香蕉网| 无码国内精品久久人妻麻豆按摩| 国产精品久久久久影院色| 久久久久久精品无码人妻| 国产91久久综合| 国内精品久久久久影院优| 国产99久久久国产精品小说| 亚洲国产精品久久| 久久精品国产亚洲av水果派| 亚洲精品国产第一综合99久久| 九九久久99综合一区二区| 99久久成人国产精品免费 | 狠狠色婷婷综合天天久久丁香 | 精品久久久久久亚洲精品| 天堂无码久久综合东京热| 91精品婷婷国产综合久久| 国产精品美女久久久| 色综合久久久久久久久五月| 国产精品久久久久久久久久影院 | 亚洲精品国产自在久久| 国产一区二区精品久久岳 | 久久久久人妻一区二区三区| 久久久久国产一区二区| 亚洲国产成人久久一区久久| 九九热久久免费视频| 日韩美女18网站久久精品| 久久激情亚洲精品无码?V| 久久亚洲国产精品123区| 久久综合精品国产一区二区三区|