#include <iostream>
#include<stdio.h>
#include<string.h> using namespace std;
int n,m;
int r[][]= {{,-},{,},{,},{-,}};
int l[][]= {{,},{,},{,-},{-,}};
int vis[][];
char map[][];
int x1,x2,y1,y2,ans;
int que[][];
int dfsl(int x,int y,int num1)
{
if(x==x2&&y==y2)
return ++num1;
if(x<||x>=n||y<||y>=m||map[x][y]=='#')
return ;
ans=(ans+)%;
int temp=;
while()
{
temp=dfsl(x+l[ans][],y+l[ans][],num1+);
if(temp>)
break;
ans=(ans+)%;
}
return temp; } int dfsr(int x,int y,int num2)
{
if(x==x2&&y==y2)
return ++num2;
if(x<||x>n||y<||y>m||map[x][y]=='#')
return ;
ans=(ans+)%;
int temp=;
while()
{
temp=dfsr(x+r[ans][],y+r[ans][],num2+);
if(temp>)
break;
ans=(ans+)%;
}
return temp; } int bfs()
{
int fir=,sec=;
que[sec][]=x1;
que[sec++][]=y1;
vis[x1][y1]=;
int step=;
while(fir<sec&&!vis[x2][y2])
{
int tmp=sec;
step++;
while(fir<tmp&&!vis[x2][y2])
{
int x=que[fir][];
int y=que[fir++][];
for(int i=; i<; i++)
{
int x1=x+r[i][];
int y1=y+r[i][];
if(x1>=&&x1<n&&y1>=&&y1<m&&!vis[x1][y1]&&map[x1][y1]!='#')
{
que[sec][]=x1;
que[sec++][]=y1;
vis[x1][y1]=;
}
}
}
}
return step;
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&m,&n);
memset(que,,sizeof(que));
memset(vis,,sizeof(vis));
for(int i=; i<n; i++)
{
// scanf("%s",map[i]);
for(int j=; j<m; j++)
{
cin>>map[i][j];
if(map[i][j]=='S')
{
x1=i;
y1=j;
}
if(map[i][j]=='E')
{
x2=i;
y2=j;
}
}
}
ans=;
printf("%d",dfsl(x1,y1,));
ans=;
printf(" %d",dfsr(x1,y1,));
printf(" %d\n",bfs());
}
return ;
}

Time Limit: 1000 MS Memory Limit: 65536 KB

64-bit integer IO format: %I64d , %I64u   Java class name: Main

[Submit] [Status] [Discuss]

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 题意:
S为起点 E为终点 #不可以走 以左为优先方向 以右为优先方向 最短 的步骤 求最短步骤都要用广搜

poj 3083 Children of th的更多相关文章

  1. POJ 3083 -- Children of the Candy Corn(DFS+BFS)TLE

    POJ 3083 -- Children of the Candy Corn(DFS+BFS) 题意: 给定一个迷宫,S是起点,E是终点,#是墙不可走,.可以走 1)先输出左转优先时,从S到E的步数 ...

  2. poj 3083 Children of the Candy Corn(DFS+BFS)

    做了1天,总是各种错误,很无语 最后还是参考大神的方法 题目:http://poj.org/problem?id=3083 题意:从s到e找分别按照左侧优先和右侧优先的最短路径,和实际的最短路径 DF ...

  3. POJ:3083 Children of the Candy Corn(bfs+dfs)

    http://poj.org/problem?id=3083 Description The cornfield maze is a popular Halloween treat. Visitors ...

  4. POJ 3083 Children of the Candy Corn (DFS + BFS + 模拟)

    题目链接:http://poj.org/problem?id=3083 题意: 这里有一个w * h的迷宫,给你入口和出口,让你分别求以下三种情况时,到达出口的步数(总步数包括入口和出口): 第一种: ...

  5. poj 3083 Children of the Candy Corn 【条件约束dfs搜索 + bfs搜索】【复习搜索题目一定要看这道题目】

    题目地址:http://poj.org/problem?id=3083 Sample Input 2 8 8 ######## #......# #.####.# #.####.# #.####.# ...

  6. poj 3083 Children of the Candy Corn

    点击打开链接 Children of the Candy Corn Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8288 ...

  7. POJ 3083 Children of the Candy Corn bfs和dfs

      Children of the Candy Corn Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8102   Acc ...

  8. poj 3083 Children of the Candy Corn (广搜,模拟,简单)

    题目 靠墙走用 模拟,我写的是靠左走,因为靠右走相当于 靠左走从终点走到起点. 最短路径 用bfs. #define _CRT_SECURE_NO_WARNINGS #include<stdio ...

  9. POJ 3083 Children of the Candy Corn 解题报告

    最短用BFS即可.关于左手走和右手走也很容易理解,走的顺序是左上右下. 值得注意的是,从起点到终点的右手走法和从终点到起点的左手走法步数是一样. 所以写一个左手走法就好了.贴代码,0MS #inclu ...

随机推荐

  1. mount重新挂载为写模式

    mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system mount -o remount,rw -t rootfs rootfs /

  2. 全局组建封装(挂载到vue实例的原型中,通过this访问)

    主题:组建的封装  一:install注册的全局封装(v-grid九宫格组建)               1.九宫格的封装主要有三个api 点击功能 每行个数 是否隐藏边框              ...

  3. [Jmeter] 用xsltproc生成html格式的报告

    1.下载xsltproc 下载地址:ftp://ftp.zlatkovic.com/libxml/libxslt-1.1.26.win32.zip 其中包含我们所需要的xsltproc可执行文件:xs ...

  4. Python之路(第二篇):Python基本数据类型字符串(一)

    一.基础 1.编码 UTF-8:中文占3个字节 GBK:中文占2个字节 Unicode.UTF-8.GBK三者关系 ascii码是只能表示英文字符,用8个字节表示英文,unicode是统一码,世界通用 ...

  5. jmeter使用HTTP代理服务器

    浏览器>web服务器 浏览器>HTTP代理服务器>web服务器 jmeter>HTTP代理服务器>web服务器 浏览器>jmeter HTTP服务器>web服 ...

  6. maven下载的jar相应pom文件下载不完整问题。

    今天遇到一个奇葩问题: 同样的项目,我启动报错 : 某个class文件找不到.. 查找maven 依赖也的确没有找到 对应的jar 包. 查找同事项目,可以看到该class对应的 jar 包 是 lo ...

  7. STL基础1:vector

    #include <iostream> #include <vector> #include <algorithm> #include <numeric> ...

  8. 解决textarea 输出有空格问题

    我们在使用textarea标签输出的时候,经常会出现前后都有空格.使用trim()处理也不行. 这个原因是因为 我们在编写textarea标签对的时候使用了换行. 解决方法:就是<textare ...

  9. 关于xp操作系统下使用VC6++编写的上位机软件在win10中运行的问题

    将代码拷贝到win10操作系统中,在vs2015环境中重新编译即可. 编译生成的exe出现终止时考虑mscomm控件是否注册. 当win10环境64位操作系统时,将以下四个文件放置于C:\Window ...

  10. 2019.01.17 bzoj1854: [Scoi2010]游戏(二分图匹配)

    传送门 二分图匹配菜题. 题意:nnn个二元组(xi,yi)(x_i,y_i)(xi​,yi​),每个二元组可以选一个数总共nnn个数aia_iai​,问将aia_iai​排好序之后从111开始最多可 ...