#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. git报“commiter email "root@localhost.localdomain"does not match your user account”

    首先检查账户邮箱配置是否正确,检查方法: git config --list 发现邮箱及帐号配置正确,但是git push时仍然报如题错误: 原因:git执行add.commit 时已经记录下了做了该 ...

  2. 定时任务起的java进程没有释放导致oracle的问题not availavle & out of memory

    最近发现一个问题,我们设置了一个定时任务,用于每天的对账,每天的对账都是启动一个java程序(jar包),时间久了,出现下面的问题: 有很多CardPaymentBatch.jar进程驻留在系统当中, ...

  3. javascript数组中数字和非数字下标的区别(转)

    http://blog.csdn.net/qq_27461663/article/details/52014911 考完试后闲来无事,想起好多天没写js了,于是打算实践一下最近看到的一些好玩的点子.结 ...

  4. Minimum Window Substring LT76

    Given a string S and a string T, find the minimum window in S which will contain all the characters ...

  5. 调用webservice时,产生android.os.NetworkOnMainThreadException错误

    android.os.NetworkOnMainThreadException 网上搜索后知道是因为版本问题,在4.0之后在主线程里面执行Http请求都会报这个错,也许是怕Http请求时间太长造成程序 ...

  6. Globalization and accessibility for tile and toast notifications (Windows Store apps)

    http://msdn.microsoft.com/en-us/library/windows/apps/hh831183.aspx 做 HighContrast时,采用以下分目录方式: /Proje ...

  7. Java第11章笔记

    什么是类,什么是对象 举例说明什么是类,什么是对象? 一句话:万物皆对象 类的概念:类是具有相同属性和服务的一组对象的集合. 1.为属于该类的所有对象提供了统一的抽象描述,其内部包括属性和服务两个部分 ...

  8. sql创建备份表和复制数据到备份表

    1.复制表结构及数据到新表CREATE TABLE 新表 SELECT * FROM 旧表 这种方法会将oldtable中所有的内容都拷贝过来,当然我们可以用delete from newtable; ...

  9. mybatis分页插件Mybatis_PageHelper 简单案例

    源码地址(官网,文档) 使用条件: 支持mybatis 3.1.0+ sql 解析工具(jsqlparser.jar) 下载 Mybatis_PageHelper  版本随意,反正我用的5.0.0 m ...

  10. Le Chapitre V

    Chaque jour j'apprennais quelque chose sur la planète, sur le départ, sur le voyage. Ca venait tout ...