#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. 【Redis】Redis-benchmark测试Redis性能

    Redis-benchmark是官方自带的Redis性能测试工具,可以有效的测试Redis服务的性能. 使用说明如下: Usage: redis-benchmark [-h <host>] ...

  2. 459. Repeated Substring Pattern

    https://leetcode.com/problems/repeated-substring-pattern/#/description Given a non-empty string chec ...

  3. AOP 和 前置通知,后置通知

    Spring 1.AOP:中文名称面向切面编程 2.英文名称:(Aspect Oriented Programming) 3.正常程序执行流程都是纵向执行流程 3.1 又叫面向切面编程,在原有纵向执行 ...

  4. django之http

    一 http协议介绍 http协议(Hyper Text Transfer Protocol):超文本传输协议,是基于应用层的面向对象协议,靠tcp协议和IP来传输数据,请求和响应是http协议的基本 ...

  5. 2018.12.19 codeforces 1092F. Tree with Maximum Cost(换根dp)

    传送门 sbsbsb树形dpdpdp题. 题意简述:给出一棵边权为1的树,允许选任意一个点vvv为根,求∑i=1ndist(i,v)∗ai\sum_{i=1}^ndist(i,v)*a_i∑i=1n​ ...

  6. CHAPITRE II

    J'ai ainsi vécu seul, sans personne avec qui parler véritablement, jusqu'à une panne[pan][机]故障 dans ...

  7. R语言的文件写入

    R语言的文件写入 官方文档介绍如下: write.table(x, file = "", append = FALSE, quote = TRUE, sep = " &q ...

  8. 安卓中的makefile文件打印调试信息

    在安卓源码的makefile中有很多变量的值不方便确定,那么可以通过调试makefile文件来确定这些变量的值. $(warning  " TARGET_BOARD_PLATFORM =  ...

  9. php输出语句

    看不懂? 抄一遍代码吧. echo 和 print 在 PHP 中有两个基本的输出方式: echo 和 print echo 和 print 区别: echo - 可以输出一个或多个字符串 print ...

  10. php 制作二维码 phpqrcode.php

    phpqrcode.php 下载地址:https://sourceforge.net/projects/phpqrcode/ //测试可行 utf-8格式 <?php header(" ...