hdu 1728 逃离迷宫 [ dfs ]
逃离迷宫
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 17478 Accepted Submission(s): 4247
第1行为两个整数m, n (1 ≤ m, n ≤ 100),分别表示迷宫的行数和列数,接下来m行,每行包括n个字符,其中字符'.'表示该位置为空地,字符'*'表示该位置为障碍,输入数据中只有这两种字符,每组测试数据的最后一行为5个整数k, x1, y1, x2, y2 (1 ≤ k ≤ 10, 1 ≤ x1, x2 ≤ n, 1 ≤ y1, y2 ≤ m),其中k表示gloria最多能转的弯数,(x1, y1), (x2, y2)表示两个位置,其中x1,x2对应列,y1, y2对应行。
5 5
...**
*.**.
.....
.....
*....
1 1 1 1 3
5 5
...**
*.**.
.....
.....
*....
2 1 1 1 3
yes
| 13261396 | 2015-03-27 21:05:25 | Accepted | 1728 | 93MS | 4272K | 2241 B | G++ | czy |
#include <cstdio>
#include <cstring>
#include <stack>
#include <vector>
#include <map>
#include <algorithm> #define ll long long
int const N = ;
int const M = ;
int const inf = ;
ll const mod = ; using namespace std; int T;
int n,m;
int k;
int vis[N][N][][]; struct PP
{
int x;
int y;
int operator ==(const PP &b) const
{
if(x==b.x && y==b.y) return ;
else return ;
}
}; PP st,en;
char s[N][N];
int dirx[]={-,,,};
int diry[]={,,,-};
int flag; void ini()
{
int i,j;
flag=;
scanf("%d%d",&n,&m);
memset(vis,,sizeof(vis));
for(i=;i<=n+;i++){
for(j=;j<=m+;j++){
s[i][j]='*';
}
}
for(i=;i<=n;i++){
scanf("%s",s[i]+);
}
scanf("%d%d%d%d%d",&k,&st.y,&st.x,&en.y,&en.x);
} void dfs(PP te,int d,int num)
{ if(num>k){
return;
}
if(te==en){
flag=;return;
}
int i;
PP nt;
for(i=;i<;i++){
nt.x=te.x+dirx[i];
nt.y=te.y+diry[i];
if(s[nt.x][nt.y]=='.'){
if(i==d){
if(vis[nt.x][nt.y][num][i]==) continue;
vis[nt.x][nt.y][num][i]=;
dfs(nt,i,num);
}
else{
if(vis[nt.x][nt.y][num+][i]==) continue;
vis[nt.x][nt.y][num+][i]=;
dfs(nt,i,num+);
}
if(flag==) return;
}
}
} void solve()
{
int d;
PP nt;
if(nt==en){
flag=;return;
}
for(d=;d<;d++){
if(flag==) return;
nt.x=st.x+dirx[d];
nt.y=st.y+diry[d];
if(s[nt.x][nt.y]=='.'){
vis[nt.x][nt.y][][d]=;
dfs(nt,d,);
}
}
} void out()
{
if(flag==){
printf("yes\n");
}
else{
printf("no\n");
}
} int main()
{
//freopen("data.in","r",stdin);
// freopen("data.out","w",stdout);
scanf("%d",&T);
//for(int cnt=1;cnt<=T;cnt++)
while(T--)
//while(scanf("%d%d",&n,&sum)!=EOF)
{
ini();
solve();
out();
}
}
hdu 1728 逃离迷宫 [ dfs ]的更多相关文章
- HDU 1728 逃离迷宫(DFS经典题,比赛手残写废题)
逃离迷宫 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- HDU 1728 逃离迷宫(DFS||BFS)
逃离迷宫 Problem Description 给定一个m × n (m行, n列)的迷宫,迷宫中有两个位置,gloria想从迷宫的一个位置走到另外一个位置,当然迷宫中有些地方是空地,gloria可 ...
- hdu 1728 逃离迷宫 bfs记转向
题链:http://acm.hdu.edu.cn/showproblem.php?pid=1728 逃离迷宫 Time Limit: 1000/1000 MS (Java/Others) Mem ...
- hdu 1728 逃离迷宫 bfs记步数
题链:http://acm.hdu.edu.cn/showproblem.php?pid=1728 逃离迷宫 Time Limit: 1000/1000 MS (Java/Others) Mem ...
- HDU 1728 逃离迷宫(DFS)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=1728 题目: 逃离迷宫 Time Limit: 1000/1000 MS (Java/Others) ...
- hdu 1728:逃离迷宫(DFS,剪枝)
逃离迷宫 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- HDU 1728 逃离迷宫
[题目描述 - Problem Description] 给定一个m × n (m行, n列)的迷宫,迷宫中有两个位置,gloria想从迷宫的一个位置走到另外一个位置,当然迷宫中有些地方是空地,glo ...
- hdu 1728 逃离迷宫 (BFS)
逃离迷宫 Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submissi ...
- hdu 1728 逃离迷宫(dFS+优先队列)
求转弯最少的走路方式!!!! #include<stdio.h> #include<string.h> #include<queue> using namespac ...
随机推荐
- 在WIN7下解决coursera视频无法播放问题
https://blog.csdn.net/u012509485/article/details/78459584在WIN7下解决coursera视频无法播放问题2019/1/20 23:18 最近C ...
- Failure to transfer org.apache.maven.plugins:maven-compiler-plugin:jar:2.5.1
Mac上写了一段基于Maven的java代码. 上传Git后,在windows上pull下来,eclipse里面各种错误. ArtifactTransferException:Failure to t ...
- 洛谷 P2866 [USACO06NOV]糟糕的一天Bad Hair Day
题目描述 Some of Farmer John's N cows (1 ≤ N ≤ 80,000) are having a bad hair day! Since each cow is self ...
- COGS 1406. 邻居年龄排序[Age Sort,UVa 11462](水题日常)
★ 输入文件:AgeSort.in 输出文件:AgeSort.out 简单对比时间限制:1 s 内存限制:2 MB [题目描述] Mr.Zero(CH)喜闻乐见地得到了一台内存大大增强 ...
- css-test
transition-content See the Pen NLOgVR by nakata139@gmail.com (@deepblue1982) on CodePen.
- Elasticsearch学习(二)————搜索
Elasticsearch1.query string search1.1.搜索全部// 1. GET http://ip:9200/test/test/_search 结果: { "too ...
- mount nfs 各版本之间的转换
[root@one1-fst-hx ~]# mount.nfs 182.168.2.49:/mnt/sdb/nfs /mnt/nfs2/ nomand,-o vers=3[root@one1-fst- ...
- 指针-动态开点&合并线段树
一个知识点不在一道题里说是没有灵魂的 线段树是用来处理区间信息的咯 但是往往因为需要4倍空间让许多人退却,而动态开点的线段树就非常棒 仿佛只用2倍就可以咯 指针保存位置,即节点信息,是很舒适的,所以用 ...
- IFE春季班第一阶段任务(请仔细阅读)
第一阶段的主要目标是帮助大家 了解.认识.学习.掌握HTML及CSS.第一阶段任务从 3月14日 开始,持续到 4月3日.当然,您也可以在这个时间以后继续自行实践练习. 第一阶段任务一共有 12 个题 ...
- [Usaco2009 Nov]lights
题目描述: 给出$n$,$m$,表示有$n$盏灯和$m$条奇怪的电线,按下电线一段的灯后另一端会有影响. 求最少按几次. 题解: 高消解异或方程组,得到一堆自由元后搜索自由元状态,然后不断更新答案. ...