POJ-3083 Children of the Candy Corn problem-solving report (search) wide search deep search Maze __output

Source: Internet
Author: User
Tags stdin

B-children of the Candy CornTime Limit:1000MSMemory Limit:65536KB64bit IO Format:%I64D &%i64u http://openoj.awaysoft.com:8080/judge/problem/viewProblem.action?id=28859 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, a nd other terrors on their quest to find the exit.

One popular maze-walking strategy guarantees that visitor would eventually find the exit. Simply choose either the right or left wall, and follow it. Course, there ' s no guarantee which strategy (left or right) would be better, and the path taken is seldom the most effic Ient. (It also doesn ' t work on mazes with exits "that is are not on the edge; those types of mazes are not represented at this probl EM.)

As the proprieter of a cornfield that's about to being converted into a maze, your ' d like to have a computer program that can Determine the left and right-hand paths along with the shortest path so, can figure out which layout has the best Chance of confounding visitors.

Input input to this problem would begin with a-line containing a single integer n indicating the number of mazes. Each maze would consist of one line with a width, w, and Height, h (3 <= W, H <=), followed by H lines of W Charac Ters each of that represent the maze layout. Walls are represented by hash marks (' # '), Empty spaces by periods ('. '), the "Start by" an ' S ' and "Exit by" an ' E '.

exactly one ' S ' and one ' E ' would be present in the maze, and they'll always be located along one of the maze E Dges and never in a corner. The maze is fully enclosed by walls (' # '), with the only openings being the ' S ' and ' E '. The ' S ' and ' E ' would also be separated by at least one wall (' # ').

You may assume this maze exit is always reachable to 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 wo Uld visit (including the ' S ' and ' E ') for [in order] the left, right, and shortest paths, separated by a single spaces each . Movement from one square to another are 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

Panax 5 5
17 17 9

Hint

Finally the topic meaning to see understand = =.

Left first: Each will be a step, priority to walk it in the left direction; Right first: Every step of the line, priority to walk its right direction;

If the priority direction does not work, then according to the diagram direction in turn to judge;

Source of report: http://blog.csdn.net/angle555945/article/details/7303207

#include <stdio.h> #include <memory.h> const int maxn=50;
int L_dfs ();
int R_dfs ();
int S_bfs (); int W,H,X1,Y1,X2,Y2,Q[MAXN*MAXN],FA[MAXN][MAXN], dlx[4]={0,-1,0,1},dly[4]={-1,0,1,0}, drx[4]={0,-1,0,1},dry[4]={
1,0,-1,0};
Char map[maxn][maxn],vis[maxn][maxn]={{0}};
	int main () {//Freopen ("In.txt", "R", stdin);
	int t,i,j;
	scanf ("%d", &t);
		while (t--) {scanf ("%d%d", &w,&h);
			for (i=0;i 


  This is its own version and feels a little improved.

#include <stdio.h> #include <memory.h> const int maxn=50;
int Lr_dfs (int kg);
int BFS ();
int W,H,X1,Y1,X2,Y2,Q[MAXN*MAXN],DIS[MAXN*MAXN],VIS[MAXN*MAXN];
int FA[MAXN][MAXN],VIS[MAXN][MAXN];	int dlx[4]={0,-1,0,1},dly[4]={-1,0,1,0}, drx[4]={0,-1,0,1},dry[4]={1,0,-1,0};
Dlx[i]=drx[i], dly[i]=dry[(i+2)%4];
Char MAP[MAXN][MAXN];
	int main () {//Freopen ("In.txt", "R", stdin);
	int t,i,j;
	scanf ("%d", &t);
		while (t--) {scanf ("%d%d", &w,&h);
			for (i=0;i 


Summarize:

0
/ | \
1 2 3
/ | | \   \
4 5 6 7 8

(BFS Chart)
Issues to consider.
When ①bfs, prevent the walk, need a vis array mark, and in the judgment to avoid short-circuit operator interference;
② Search, find the exit after the need to find, through the global variable OK to control, especially in the DFS;
③ more use printf debugging intermediate process to find the cause of the error;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.