poj 3083 Children of th
#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
Description
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
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
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的更多相关文章
- POJ 3083 -- Children of the Candy Corn(DFS+BFS)TLE
POJ 3083 -- Children of the Candy Corn(DFS+BFS) 题意: 给定一个迷宫,S是起点,E是终点,#是墙不可走,.可以走 1)先输出左转优先时,从S到E的步数 ...
- poj 3083 Children of the Candy Corn(DFS+BFS)
做了1天,总是各种错误,很无语 最后还是参考大神的方法 题目:http://poj.org/problem?id=3083 题意:从s到e找分别按照左侧优先和右侧优先的最短路径,和实际的最短路径 DF ...
- 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 ...
- POJ 3083 Children of the Candy Corn (DFS + BFS + 模拟)
题目链接:http://poj.org/problem?id=3083 题意: 这里有一个w * h的迷宫,给你入口和出口,让你分别求以下三种情况时,到达出口的步数(总步数包括入口和出口): 第一种: ...
- poj 3083 Children of the Candy Corn 【条件约束dfs搜索 + bfs搜索】【复习搜索题目一定要看这道题目】
题目地址:http://poj.org/problem?id=3083 Sample Input 2 8 8 ######## #......# #.####.# #.####.# #.####.# ...
- poj 3083 Children of the Candy Corn
点击打开链接 Children of the Candy Corn Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8288 ...
- POJ 3083 Children of the Candy Corn bfs和dfs
Children of the Candy Corn Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8102 Acc ...
- poj 3083 Children of the Candy Corn (广搜,模拟,简单)
题目 靠墙走用 模拟,我写的是靠左走,因为靠右走相当于 靠左走从终点走到起点. 最短路径 用bfs. #define _CRT_SECURE_NO_WARNINGS #include<stdio ...
- POJ 3083 Children of the Candy Corn 解题报告
最短用BFS即可.关于左手走和右手走也很容易理解,走的顺序是左上右下. 值得注意的是,从起点到终点的右手走法和从终点到起点的左手走法步数是一样. 所以写一个左手走法就好了.贴代码,0MS #inclu ...
随机推荐
- BZOJ1047或洛谷2216 [HAOI2007]理想的正方形
BZOJ原题链接 洛谷原题链接 显然可以用数据结构或\(ST\)表或单调队列来维护最值. 这里采用单调队列来维护. 先用单调队列维护每一行的最大值和最小值,区间长为正方形长度. 再用单调队列维护之前维 ...
- 开发中,android手机WIFI无法使用,无SIM卡故障解决
用eclipse 开发android中,突然出现,android手机WIFI无法使用,无SIM卡故障解决 发现故障后,想办法刷机(没有成功),触点清洁都搞了. 最后恢复出厂设置居然解决了,留资料给同行 ...
- MySQL用户及权限管理
查看用户 mysql>SELECT user, host FROM mysql.user; # 检索mysql数据库中的user表 % 表示所有主机的IP 查看当前用户 mysql> se ...
- Python之路(第五篇) Python基本数据类型集合、格式化、函数
一.变量总结 1.1 变量定义 记录某种状态或者数值,并用某个名称代表这个数值或状态. 1.2 变量在内存中的表现形式 Python 中一切皆为对象,数字是对象,列表是对象,函数也是对象,任何东西都是 ...
- 拼图类APP原型模板分享——简拼
简拼是一款记录美好.抒写情怀的拼图APP,模板设计风格简约文艺,种类齐全. 此原型模板所用到的组件有标签组.水平分隔线.圆形工具.交互动作有结合标签组实现页面跳转,选择组件触发按钮状态变化等. 此原型 ...
- 各种编译不通过xcode
2017-08-24 Apple Mach-O Linker (Id) Error Linker command failed with exit code 1 (use -v to see invo ...
- 【Linux】OpenSSL 安装
OpenSSL 简介 OpenSSL 是一个安全套接字层密码库,囊括主要的密码算法.常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用. OpenSSL 安装 环境:L ...
- 2018.10.30 NOIP模拟 排列树(树形dp+组合数学)
传送门 考试的时候乱搞过了. 其实题目就是让你求拓扑排序方案数. 直接树形dpdpdp然后组合数转移一下就行了. 乱搞代码
- 3.The significance of Books 书本的意义
3.The significance of Books 书本的意义 (1)A bookless life is an imcomplete life.Books influence the depth ...
- Router types
Inq-n. Flits are stored at the input of the router. Each input unit is connected to the switch by as ...