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 ...
随机推荐
- 序列化pickle模块
1.pickle模块 pickle.dumps() 和pickle.loads() import pickle f = open('112.pkl','w') a = {'name':2,2:3,3: ...
- 【学习笔记】比特(bit)、字,字节(B)存储单位之间的关系+其与操作系统位数的关系+不同编译器编译方式下数据类型的表示范围
1.在表示网络传输速度中与表示存储单位的不同: 表示存储单位时:1kB=1024B,但在网络中表示传输速度是1KB=1000B 2.下面介绍表示存储单位时的关系及其与操作系统位数的关系: 1B=8bi ...
- Android 常见的工具类
/** * Wifi 管理类 * * @author Administrator * 使用方法 * WifiManagerUtils wifiManager = new WifiManagerUtil ...
- mongoDB学习初步总结
What? 最受欢迎的非关系型数据库之一.面向文档的数据库,在存储乎数据方面与关系型数据库有着本质的区别. Why? 简单易用 对多变的业务需求,适应性强于SQL型DB 性能 复制 索引 分片 丰富的 ...
- MyBatis学习(四)
前言 最近比较松懈,下班回家后也懒得学习了.今晚实在是看不下去了,争取时间学习.社会上有这么多的资源,就看谁能抢的多吧.今天就说说MyBatis的动态SQL吧 正文 动态 SQL 通常要做的事情是有条 ...
- Python 语言规范
Python 语言规范 pychecker 对你的代码运行pychecker 定义: pychecker 是一个在Python 源代码中查找bug 的工具. 对于C 和C++这样的不那 么动态的( ...
- $.noconflict() 有什么用处
jQuery默认使用"$"操作符,prototype等其他框架也是是使用"$",于是,如果jQuery在其他库之后引入,那么jQuery将获得"$&q ...
- Graveyard LA3708
白书第一章例题4 思维. 先固定一点不动,假设最后一共N个点,那么编号为0,1,...N-1, 0不动,原来的n个点分别占据i/n*N的位置(记为pos),移动到pos四舍五入的位置即可. 证明一:有 ...
- 一次执行两个npm "start": "concurrently 'npm:dev' 'npm:json-server'"
用的这个程序 concurrently 说是再有异步的时候,&& 就不好使,而且&& 也不能执行npm 只能执行命令 官方地址:https://www.npmjs.co ...
- nodejs 安装 淘宝镜像
临时使用 npm --registry https://registry.npm.taobao.org install express 2.持久使用 npm config set registry h ...