青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

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
挺簡單的一個搜索題目,廣搜和深搜都要用
題目意思,有一個迷宮,現在想知道總是沿著迷宮左側墻壁走的能走多少步,沿著迷宮右側墻壁走的能走多少步
最少走多少步能出去
我覺著這個題目關鍵在于如何處理怎樣沿著左右墻壁走
我一開始以為設好總是右拐左拐的方向就行了,結果樣例就不過,最后輸出一看,有個地方一直來回走了,死循環了
這里怎么處理呢?
我也不會,網上看到神一般的代碼
 for (i=xx+1;i>=xx-2;i--)
{
  j=(8+i)&3;//????
}
真心不明白啥意思,等弄懂了再回來寫思路
除了這種方法,還沒想到別的方法,額,糾結了
  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 閱讀(834) 評論(3)  編輯 收藏 引用

評論

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

額,呵呵,看看我的題解
http://www.shnenglu.com/ArcTan/articles/169695.html
  回復  更多評論   

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

嚓,位運算我還是不懂………………
那個(8+i)&3應該就跟我那個循環去找一樣的哈。  回復  更多評論   

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

@王私江
(8+i)&3 相當于是 取余3的意思 因為 3 的 二進制是 000011 和(8+i)   回復  更多評論   


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


<2025年11月>
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456

導航

統計

常用鏈接

留言簿

文章檔案(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
  • 評論內容較長,點擊標題查看
  • --王私江
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            亚洲午夜在线| 狠狠爱综合网| 亚洲免费成人av| 99在线热播精品免费99热| 国产九九精品视频| 欧美国产成人精品| 欧美亚洲成人网| 免费欧美日韩| 国产精品一区二区你懂得| 欧美高潮视频| 国产乱码精品一区二区三区av | 性色av香蕉一区二区| 亚洲激情欧美| 香蕉久久夜色精品国产| 一本色道久久加勒比88综合| 欧美在线一区二区三区| 亚洲一区二区三区精品在线| 男人插女人欧美| 久久久久综合网| 国产精品福利在线| 亚洲国产欧美久久| 狠狠操狠狠色综合网| 一本久久a久久免费精品不卡| 狠狠久久五月精品中文字幕| 正在播放亚洲一区| 久久久人成影片一区二区三区| 欧美日韩中文字幕在线视频| 免费黄网站欧美| 国产午夜精品在线观看| 亚洲欧洲在线观看| 在线欧美电影| 久久精品国亚洲| 久久久久免费| 国产伦精品一区二区三区在线观看| 亚洲区一区二区三区| 亚洲第一网站免费视频| 久久aⅴ乱码一区二区三区| 香蕉久久久久久久av网站 | 久久久999国产| 国产精品亚洲综合| 在线一区二区日韩| 一本久道久久综合狠狠爱| 免费亚洲婷婷| 亚洲国产精品黑人久久久 | 午夜精品一区二区三区在线视| 亚洲一区二区三区在线视频| 欧美日韩1080p| 亚洲精品一二三| 一区二区三区鲁丝不卡| 欧美国产综合一区二区| 亚洲人成网站精品片在线观看| 亚洲精品乱码久久久久久蜜桃麻豆| 美女91精品| 最新成人av在线| 99综合视频| 国产精品白丝jk黑袜喷水| 亚洲午夜av在线| 久久大综合网| 亚洲国产一区二区精品专区| 欧美精品色一区二区三区| 99re6这里只有精品| 午夜久久资源| 一区二区三区在线视频观看| 媚黑女一区二区| 亚洲久久一区| 久久av一区二区三区亚洲| 国内精品久久久久国产盗摄免费观看完整版 | 嫩草影视亚洲| 99国产精品视频免费观看| 午夜日韩激情| 狠狠色伊人亚洲综合成人| 老鸭窝毛片一区二区三区| 亚洲国产老妈| 亚洲欧美日韩久久精品| 国模私拍视频一区| 欧美激情一区二区三区高清视频| 亚洲最黄网站| 久久久精品一品道一区| 亚洲精品国产日韩| 国产精品女主播一区二区三区| 久久精品人人| 99精品视频一区二区三区| 久久精品国产精品| 日韩视频在线观看免费| 国产乱码精品一区二区三区五月婷| 久久久亚洲一区| 99视频热这里只有精品免费| 久久久久久噜噜噜久久久精品| 亚洲国产成人一区| 国产精品久久九九| 亚洲一区二区三区777| 欧美成人性生活| 亚洲综合清纯丝袜自拍| 免费不卡在线观看av| 亚洲视频在线一区| 精品成人乱色一区二区| 国产精品久久久久久久久久ktv| 久久噜噜噜精品国产亚洲综合| 一本久久精品一区二区| 米奇777在线欧美播放| 亚洲先锋成人| 亚洲欧洲精品一区二区| 国产欧美 在线欧美| 欧美激情综合网| 久久九九久久九九| 亚洲在线视频网站| 亚洲日本中文字幕区| 女女同性精品视频| 久久久无码精品亚洲日韩按摩| 亚洲综合成人在线| 亚洲黄色成人| 狠狠做深爱婷婷久久综合一区| 国产精品久久夜| 欧美日韩国产综合新一区| 免费不卡在线视频| 久久婷婷麻豆| 久久精彩视频| 欧美亚洲综合久久| 亚洲免费一级电影| 亚洲图片欧美一区| 亚洲视频一二区| 一本色道久久综合亚洲精品婷婷 | 一区二区三区无毛| 国产视频综合在线| 国产精品亚洲综合一区在线观看| 欧美日韩精品| 欧美丰满高潮xxxx喷水动漫| 老巨人导航500精品| 久久免费精品视频| 久热精品在线| 欧美+日本+国产+在线a∨观看| 久久―日本道色综合久久| 久久成人av少妇免费| 欧美一区二区三区男人的天堂 | 一区二区高清视频| 一级成人国产| 一区二区免费在线观看| 亚洲毛片在线看| 亚洲毛片一区| 在线视频欧美一区| 亚洲小说区图片区| 亚洲欧美成人在线| 午夜久久福利| 久久精品国产久精国产爱| 久久狠狠婷婷| 免费亚洲一区二区| 亚洲黄色性网站| 日韩视频三区| 亚洲欧美精品一区| 久久国产精品色婷婷| 久久久夜精品| 欧美精品一区在线发布| 欧美日韩亚洲一区二区三区在线| 国产精品成人观看视频免费| 国产日韩欧美另类| 亚洲国产裸拍裸体视频在线观看乱了中文| 91久久精品一区二区别| 亚洲精品少妇30p| 亚洲调教视频在线观看| 久久国产精品久久精品国产| 女女同性精品视频| 夜夜嗨一区二区| 欧美中文在线免费| 亚洲国产日韩欧美在线图片| 久久精品99无色码中文字幕| 美女91精品| 日韩一级免费观看| 午夜精品亚洲一区二区三区嫩草| 久久精品亚洲一区二区| 欧美黄色网络| 国产精品综合久久久| 在线免费观看视频一区| 亚洲视频一起| 美女网站在线免费欧美精品| 99re66热这里只有精品3直播| 亚洲欧美文学| 欧美精品在线看| 国内成人精品2018免费看| 夜夜爽99久久国产综合精品女不卡| 欧美一级专区| 亚洲电影在线播放| 亚洲一级高清| 欧美成人一区二免费视频软件| 欧美丝袜一区二区三区| 亚洲成在人线av| 欧美一区二区三区四区在线观看地址 | 亚洲在线视频观看| 欧美成人精品不卡视频在线观看 | 一区二区三区久久| 久久看片网站| 国产欧美精品一区二区色综合| 亚洲精品国精品久久99热| 欧美一区二区大片| 亚洲精品资源美女情侣酒店| 久久精品盗摄| 国产精品综合久久久| 亚洲天堂黄色| 亚洲乱码国产乱码精品精可以看 | 久久亚洲视频| 亚洲欧美一区二区视频|