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

            poj3083

            Children of the Candy Corn

            Time Limit: 1000MS Memory Limit: 65536K
            Total Submissions: 6055 Accepted: 2640

            Description

            The cornfield maze is a popular Halloween treat. Visitors are shown the entrance and must wander through the maze facing zombies, chainsaw-wielding psychopaths, hippies, and other terrors on their quest to find the exit.

            One popular maze-walking strategy guarantees that the visitor will eventually find the exit. Simply choose either the right or left wall, and follow it. Of course, there's no guarantee which strategy (left or right) will be better, and the path taken is seldom the most efficient. (It also doesn't work on mazes with exits that are not on the edge; those types of mazes are not represented in this problem.)

            As the proprieter of a cornfield that is about to be converted into a maze, you'd like to have a computer program that can determine the left and right-hand paths along with the shortest path so that you can figure out which layout has the best chance of confounding visitors.

            Input

            Input to this problem will begin with a line containing a single integer n indicating the number of mazes. Each maze will consist of one line with a width, w, and height, h (3 <= w, h <= 40), followed by h lines of w characters each that represent the maze layout. Walls are represented by hash marks ('#'), empty space by periods ('.'), the start by an 'S' and the exit by an 'E'.

            Exactly one 'S' and one 'E' will be present in the maze, and they will always be located along one of the maze edges and never in a corner. The maze will be fully enclosed by walls ('#'), with the only openings being the 'S' and 'E'. The 'S' and 'E' will also be separated by at least one wall ('#').

            You may assume that the maze exit is always reachable from the start point.

            Output

            For each maze in the input, output on a single line the number of (not necessarily unique) squares that a person would visit (including the 'S' and 'E') for (in order) the left, right, and shortest paths, separated by a single space each. Movement from one square to another is only allowed in the horizontal or vertical direction; movement along the diagonals is not allowed.

            Sample Input

            2
            8 8
            ########
            #......#
            #.####.#
            #.####.#
            #.####.#
            #.####.#
            #...#..#
            #S#E####
            9 5
            #########
            #.#.#.#.#
            S.......E
            #.#.#.#.#
            #########

            Sample Output

            37 5 5
            17 17 9
            挺簡(jiǎn)單的一個(gè)搜索題目,廣搜和深搜都要用
            題目意思,有一個(gè)迷宮,現(xiàn)在想知道總是沿著迷宮左側(cè)墻壁走的能走多少步,沿著迷宮右側(cè)墻壁走的能走多少步
            最少走多少步能出去
            我覺著這個(gè)題目關(guān)鍵在于如何處理怎樣沿著左右墻壁走
            我一開始以為設(shè)好總是右拐左拐的方向就行了,結(jié)果樣例就不過(guò),最后輸出一看,有個(gè)地方一直來(lái)回走了,死循環(huán)了
            這里怎么處理呢?
            我也不會(huì),網(wǎng)上看到神一般的代碼
             for (i=xx+1;i>=xx-2;i--)
            {
              j=(8+i)&3;//????
            }
            真心不明白啥意思,等弄懂了再回來(lái)寫思路
            除了這種方法,還沒(méi)想到別的方法,額,糾結(jié)了
              1#include<stdio.h>
              2#include<math.h>
              3#include<string.h>
              4#define MAX 45
              5#define MX  16000
              6struct node
              7{
              8    int x,y,d;
              9}
            ;
             10int w,h,sx,sy,ans1,ans2,ans3;
             11int dx[4][2]={{-1,0},{0,-1},{1,0},{0,1}};
             12int q1;
             13char map[MAX][MAX];
             14short mark[MAX][MAX];
             15int inin(int xx,int yy)
             16{
             17    return xx>=0&&xx<h&&yy>=0&&yy<w;
             18}

             19void init()
             20{
             21    int i,j;
             22    int flag;
             23    flag=0;
             24    scanf("%d%d",&w,&h);
             25    for (i=0;i<h;i++)
             26    {
             27        scanf("%s",&map[i]);
             28        for (j=0;j<w;j++)
             29        if (map[i][j]=='S'&&!flag)
             30        {
             31            sx=i;sy=j;
             32            flag=1;
             33        }

             34    }

             35    for (i=0;i<4;i++)
             36    if (inin(sx+dx[i][0],sy+dx[i][1])&&map[sx+dx[i][0]][sy+dx[i][1]]=='.')
             37    {
             38        q1=i;break;
             39    }

             40}

             41int dfs1(int x,int y,int xx)
             42{
             43    int j,i,nx,ny;
             44    if (map[x][y]=='E')
             45    {
             46        return 1;
             47    }

             48    for (i=xx+1;i>=xx-2;i--)
             49    {
             50        j=(8+i)&3;//????
             51        nx=x+dx[j][0];ny=y+dx[j][1];
             52        if ((inin(nx,ny))&&(map[nx][ny]!='#'))
             53        {
             54            return 1+dfs1(nx,ny,j);
             55        }

             56    }

             57}

             58int dfs2(int x,int y,int xx)
             59{
             60    int j,i,nx,ny;
             61    if (map[x][y]=='E')
             62        return 1;
             63    for (i=xx-1;i<=xx+2;i++)
             64    {
             65        j=(8+i)&3;//????
             66        nx=x+dx[j][0];ny=y+dx[j][1];
             67        if ((inin(nx,ny))&&(map[nx][ny]!='#'))
             68        {
             69            return 1+dfs2(nx,ny,j);
             70        }

             71    }

             72}

             73int bfs()
             74{
             75    int i,j,head,tail,nx,ny;
             76    struct node q[MX],now;
             77    memset(mark,0,sizeof(mark));
             78    head=0;tail=1;
             79    mark[sx][sy]=1;
             80    q[tail].x=sx;q[tail].y=sy;q[tail].d=1;
             81    while (head<tail)
             82    {
             83        head++;
             84        now=q[head];
             85        for (i=0;i<4;i++)
             86        {
             87            nx=now.x+dx[i][0];
             88            ny=now.y+dx[i][1];
             89            if (inin(nx,ny)&&map[nx][ny]!='#'&&!mark[nx][ny])
             90            {
             91                if (map[nx][ny]=='E')
             92                {
             93                    return now.d+1;
             94                }

             95                tail++;
             96                q[tail].x=nx;q[tail].y=ny;q[tail].d=now.d+1;
             97                mark[nx][ny]=1;
             98            }

             99        }

            100    }

            101}

            102void work()
            103{
            104    int i,j;
            105    ans3=bfs();
            106    ans1=dfs1(sx,sy,q1);
            107    ans2=dfs2(sx,sy,q1);
            108}

            109int main()
            110{
            111    int t,ii;
            112    scanf("%d",&t);
            113    for (ii=1;ii<=t;ii++)
            114    {
            115        memset(map,0,sizeof(map));
            116        init(); 
            117        work();
            118        printf("%d %d %d\n",ans1,ans2,ans3);
            119    }

            120    return 0;    
            121}

            122

            posted on 2012-03-08 20:19 jh818012 閱讀(822) 評(píng)論(3)  編輯 收藏 引用

            評(píng)論

            # re: poj3083 2012-03-31 20:53 王私江

            額,呵呵,看看我的題解
            http://www.shnenglu.com/ArcTan/articles/169695.html
              回復(fù)  更多評(píng)論   

            # re: poj3083 2012-03-31 20:57 王私江

            嚓,位運(yùn)算我還是不懂………………
            那個(gè)(8+i)&3應(yīng)該就跟我那個(gè)循環(huán)去找一樣的哈。  回復(fù)  更多評(píng)論   

            # re: poj3083 2012-08-04 21:45 游客

            @王私江
            (8+i)&3 相當(dāng)于是 取余3的意思 因?yàn)?3 的 二進(jìn)制是 000011 和(8+i)   回復(fù)  更多評(píng)論   


            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


            <2012年8月>
            2930311234
            567891011
            12131415161718
            19202122232425
            2627282930311
            2345678

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿

            文章檔案(85)

            搜索

            最新評(píng)論

            • 1.?re: poj1426
            • 我嚓,,輝哥,,居然搜到你的題解了
            • --season
            • 2.?re: poj3083
            • @王私江
              (8+i)&3 相當(dāng)于是 取余3的意思 因?yàn)?3 的 二進(jìn)制是 000011 和(8+i)
            • --游客
            • 3.?re: poj3414[未登錄](méi)
            • @王私江
              0ms
            • --jh818012
            • 4.?re: poj3414
            • 200+行,跑了多少ms呢?我的130+行哦,你菜啦,哈哈。
            • --王私江
            • 5.?re: poj1426
            • 評(píng)論內(nèi)容較長(zhǎng),點(diǎn)擊標(biāo)題查看
            • --王私江
            亚洲av日韩精品久久久久久a | 久久亚洲熟女cc98cm| 国产精品无码久久四虎| 中文字幕成人精品久久不卡| 久久精品国产亚洲Aⅴ香蕉| 久久频这里精品99香蕉久| 久久AV高清无码| 久久久精品久久久久久| 久久人人爽人人爽人人AV| 精品久久久久久无码免费| 久久精品国产亚洲AV香蕉| 国产∨亚洲V天堂无码久久久| 久久精品这里热有精品| 武侠古典久久婷婷狼人伊人| 久久人人妻人人爽人人爽| 亚洲精品国产第一综合99久久| 91精品国产高清91久久久久久| 日韩美女18网站久久精品| 波多野结衣中文字幕久久| 久久久久女教师免费一区| 久久ww精品w免费人成| 2020久久精品亚洲热综合一本 | 人人狠狠综合久久亚洲| 亚洲国产成人久久精品影视| 国产亚洲精久久久久久无码77777 国产亚洲精品久久久久秋霞 | 色综合久久最新中文字幕| 久久精品国产亚洲AV电影 | 天天影视色香欲综合久久| 久久久国产精品福利免费| 久久久久亚洲AV无码麻豆| 久久久久国产精品人妻| 久久强奷乱码老熟女网站| 青青草原1769久久免费播放| 久久天天躁狠狠躁夜夜96流白浆| 亚洲欧美日韩中文久久| 国产精品久久久久久五月尺| 亚洲人成无码久久电影网站| 亚洲精品久久久www| 少妇久久久久久被弄到高潮| 久久国产综合精品五月天| 久久久国产精华液|