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 ...
随机推荐
- EJB2的配置
1. ejb-jar.xml <?xml version="1.0" encoding="UTF-8"?> <ejb-jar xmlns=&q ...
- jQuery ajax参数后台获取不到的问题
<script type="text/javascript"> init(); var alldate = {a : "0",b:"1&q ...
- js由浅入深理解
隐式转换 + - num - 0 把num转换成number: num + "" 把num转换成字符串: ------------------------------------- ...
- LibreOJ #101. 最大流
题目描述 这是一道模板题. 给定 n nn 个点,m mm 条边,给定每条边的容量,求从点 s ss 到点 t tt 的最大流. 输入格式 第一行四个整数 n nn.m mm.s ss.t tt.接下 ...
- SEO 第十章
SEO第十章 本次课目标: 1. 站外优化方案计划 2. 常见的SEO作弊手段(黑帽) 3. 百度站长平台的使用 4. 网站流量提升和转化率提升 一.站外优化方案计划 友情链接 权重相当.行业 ...
- Android(java)学习笔记169:服务(service)之为什么使用服务
1.服务 service 长期在后台运行的进程,一般没有应用程序界面 2.进程线程和应用程序之间的关系 应用程序开启,系统启动一个Linux进程,所有的组件都是运行在同一个进程的同一个线程(mai ...
- 解决selenium.common.exception.WebDriverException:Message:'chromedriver' executable needs to be in Path
'chromedriver' executable needs to be in Path 声明:本人萌新,刚学python不久记录一下自己的坑,发出来若能帮助到一些人尽早解决问题那便是极好的,( ̄▽ ...
- js 数组过滤 filter
let res = this.list.filter(item => routeEqual(this.currentRouteObj, item) || item.name === this.$ ...
- 【整理】用JSON-server模拟REST API
用JSON-server模拟REST API https://www.cnblogs.com/ys-wuhan/p/6387791.html
- app自动化配置信息
caps={ "platformName":"Android",#平台名称 "platformVersion":"6. ...