博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 3083 Children of the Candy Corn
阅读量:4356 次
发布时间:2019-06-07

本文共 3683 字,大约阅读时间需要 12 分钟。

Children of the Candy Corn
Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu
     

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

28 8#########......##.####.##.####.##.####.##.####.##...#..##S#E####9 5##########.#.#.#.#S.......E#.#.#.#.##########

Sample Output

37 5 517 17 9

#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;int t,n,m;int sx,sy,ex,ey,ans;int b[100][100];char map[100][100];int l[4][2]= {0,1,1,0,0,-1,-1,0};int r[4][2]= {0,-1,1,0,0,1,-1,0};int dfs1(int x,int y,int step){ if(x==ex&&y==ey) return step+1; if(x<0||x>=m||y<0||y>=n||map[x][y]=='#') return 0; ans=(ans+3)%4; int temp=0; while(1) { temp=dfs1(x+l[ans][0],y+l[ans][1],step+1); if(temp>0)//temp>0代表搜索的路径是可以通过的 break; ans=(ans+1)%4; } return temp;}int dfs2(int x,int y,int step){ if(x==ex&&y==ey) return step+1; if(x<0||x>=m||y<0||y>=n||map[x][y]=='#') return 0; ans=(ans+3)%4; int temp=0; while(1) { temp=dfs2(x+r[ans][0],y+r[ans][1],step+1); if(temp>0) break; ans=(ans+1)%4; } return temp;}struct node{ int x,y,step;};int go(int x,int y){ if(x>=0&&x
=0&&y
q; st.x=x; st.y=y; st.step=1; b[st.x][st.y]=1; q.push(st); while(!q.empty()) { st=q.front(); q.pop(); if(map[st.x][st.y]=='E') return st.step; for(int k=0; k<4; k++) { ed.x=st.x+l[k][0]; ed.y=st.y+l[k][1]; if(go(ed.x,ed.y)&&map[ed.x][ed.y]!='#') { b[ed.x][ed.y]=1; ed.step=st.step+1; q.push(ed); } } }}int main(){ scanf("%d",&t); while(t--) { int i,j; memset(b,0,sizeof(b)); scanf("%d%d",&n,&m); for(i=0; i



转载于:https://www.cnblogs.com/nyist-xsk/p/7264913.html

你可能感兴趣的文章
c++ 宏定义调用不定参数的函数
查看>>
动态规划典型例题--背包问题九讲
查看>>
Qt之QHeaderView自定义排序(终极版)
查看>>
python----logging
查看>>
LBP特征 学习笔记
查看>>
与TIME_WAIT相关的几个内核参数修改测试讨论结论
查看>>
webpack构建react应用三:使用webpack Loaders 模块加载器(一)
查看>>
Java JDBC
查看>>
走势终完美 --执子之手
查看>>
补全左括号
查看>>
javascript中关于坐标 大小 的描述
查看>>
8086CPU各寄存器的用途
查看>>
AngularJs中,如何在render完成之后,执行Js脚本
查看>>
Nginx 防盗链
查看>>
如何讓Android系統顯示CJK擴展區漢字
查看>>
Android 下拉选择绑定Value和Text值
查看>>
HTML+CSS小结
查看>>
Android防止按钮连续点击
查看>>
ElasticSearch Mapping中的字段类型
查看>>
数据库中主键和外键的设计原则
查看>>