#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. linux下查看内存使用情况

    基本内存术语解读 1> free -m 同样是做为缓存,buffers和cache又有啥区别呢? 于是又查了些资料,发现buffers实际应该是叫“缓冲”,其英文解释是:A buffer is ...

  2. tomcat加载web项目报错:bad major version at offset=6

    分析原因是开发的web项目的java版本高于tomcat使用的java版本,比如我是在java1.6上开发的,但是tomcat使用的java运行环境是1.5,所以会报改错误. 转载博客如下:http: ...

  3. codeforces round#510

    蒟蒻和以前一样还是只能做 $4$ 题, 希望有一天可以 水到 $5$ 题!! 不过也终于上了蓝了...   A. Benches Description 给出$N$个座位, 每个座位上初始有$a_i$ ...

  4. POJ1659 Frogs' Neighborhood(青蛙的邻居) Havel-Hakimi定理

    Frogs' Neighborhood Time Limit: 5000MS   Memory Limit: 10000K Total Submissions: 8729   Accepted: 36 ...

  5. delphi sdk 函数个数知多少?

    pascal用了这么久 那么您知道他有多少个函数,过程? 笔者统计了一下, delphi 7    21579个delphi xe2   41145个lazarus 1.12  70987个 ==== ...

  6. [Hbase]Hbase知识大全

    HBase简介 是一个构建在HDFS上的分布式列存储系统:HBase是基于Google BigTable模型开发的,典型的key/value系统:HBase是Apache Hadoop生态系统中的重要 ...

  7. js Array 方法总结

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  8. tomcat优化(转)

    tomcat优化 Activiti  分享牛  2017-02-08  1132℃ 本文重点讲解tomcat的优化. 基本优化思路: 1.         尽量缩短单个请求的处理时间. 2.      ...

  9. TensorFlow安装时错误CondaValueError: prefix already exists: G:\softs\Anaconda\envs\tensorflow

    TensorFlow安装时,TensorFlow环境已经调好了,就是下面的第(3)步, 可我自己偏偏选了个Python3.7,因为检测到自己的Python最新版本为3.7,就手贱安了TensorFlo ...

  10. syslog系统日志、Windows事件日志监控