Tempter of the Bone--hdu1010--zoj2110
Tempter of the Bone
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 89873 Accepted Submission(s): 24438
The maze was a rectangle with sizes N by M. There was a door in the maze. At the beginning, the door was closed and it would open at the T-th second for a short period of time (less than 1 second). Therefore the doggie had to arrive at the door on exactly the T-th second. In every second, he could move one block to one of the upper, lower, left and right neighboring blocks. Once he entered a block, the ground of this block would start to sink and disappear in the next second. He could not stay at one block for more than one second, nor could he move into a visited block. Can the poor doggie survive? Please help him.
'X': a block of wall, which the doggie cannot enter;
'S': the start point of the doggie;
'D': the Door; or
'.': an empty block.
The input is terminated with three 0's. This test case is not to be processed.


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char map[][];
int m,n,bx,by,ex,ey,step,t,flag;
int mov[][]={,,,-,,,-,}; bool can(int x,int y)
{
if(x<||x>m-||y<||y>n-||map[x][y]=='X')
return false;
return true;
}
void DFS(int x,int y)
{ int xx,yy,i;
if(x==ex&&y==ey)//判断是否找到终点
{
if(step==t)
flag=;
return ;
}
if(step>t)
return ;
int dis=t-abs(ex-x)-abs(ey-y)-step;
if(dis<||dis&)//奇偶剪枝
return ;
if(flag==)
return ;//当初我就是没加这一句,在hduoj上超时了,但是在zoj上能过
for(i=;i<;i++)
{
xx=x+mov[i][];
yy=y+mov[i][];
if(can(xx,yy))
{
step++;
map[xx][yy]='X';
DFS(xx,yy);
step--;
map[xx][yy]='.';
}
}
}
int main()
{
int i,j;
while(scanf("%d%d%d",&m,&n,&t),m||n||t)
{
getchar();//吸收回车符
for(i=;i<m;i++)
{
for(j=;j<n;j++)
{
scanf("%c",&map[i][j]);
if(map[i][j]=='S')
{
bx=i;
by=j;
}
if(map[i][j]=='D')
{
ex=i;
ey=j;
}
}
getchar();
}
flag=;
step=;
int best=abs(ex-bx)+abs(ey-by);
if((best+t)&)//首先判断一下,如果最短路径和要走的步数奇偶性不同,就直接输出NO
{
printf("NO\n");
continue;
}
map[bx][by]='X';
DFS(bx,by);//深搜
if(flag)
printf("YES\n");
else
printf("NO\n");
}
return ;
}
下面看下修剪前后的时间差距
Tempter of the Bone--hdu1010--zoj2110的更多相关文章
- ZOJ2110 HDU1010 搜索 Tempter of the Bone
传送门:Tempter of the Bone 大意是给一个矩阵,叫你是否可以在给定的可走路径上不重复地走,在最后一秒走到终点. 我用了两个剪枝,且称其为简直001和剪枝002,事实证明001不要都可 ...
- hdu1010 Tempter of the Bone —— dfs+奇偶性剪枝
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 Tempter of the Bone Time Limit: 2000/1000 MS (Ja ...
- ZOJ 2110 Tempter of the Bone(条件迷宫DFS,HDU1010)
题意 一仅仅狗要逃离迷宫 能够往上下左右4个方向走 每走一步耗时1s 每一个格子仅仅能走一次且迷宫的门仅仅在t时刻打开一次 问狗是否有可能逃离这个迷宫 直接DFS 直道找到满足条件的路径 ...
- Hdu1010 Tempter of the Bone(DFS+剪枝) 2016-05-06 09:12 432人阅读 评论(0) 收藏
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- HDU1010:Tempter of the Bone(dfs+剪枝)
http://acm.hdu.edu.cn/showproblem.php?pid=1010 //题目链接 http://ycool.com/post/ymsvd2s//一个很好理解剪枝思想的博客 ...
- hdu1010 Tempter of the Bone(深搜+剪枝问题)
Tempter of the Bone Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission( ...
- HDU1010 Tempter of the Bone【小狗是否能逃生----DFS奇偶剪枝(t时刻恰好到达)】
Tempter of the Bone Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- 【HDU - 1010】Tempter of the Bone(dfs+剪枝)
Tempter of the Bone 直接上中文了 Descriptions: 暑假的时候,小明和朋友去迷宫中寻宝.然而,当他拿到宝贝时,迷宫开始剧烈震动,他感到地面正在下沉,他们意识到这是一个陷阱 ...
- hdu.1010.Tempter of the Bone(dfs+奇偶剪枝)
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- ZOJ 2110 Tempter of the Bone
Tempter of the Bone Time Limit: 2 Seconds Memory Limit: 65536 KB The doggie found a bone in an ...
随机推荐
- C#文本文件导入数据库
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Windo ...
- 微软开源PowerShell并支持Linux和OS X
[微软在开源的道路上加速度了] 从一开始的各种对抗,各种通吃,到现在开始做服务,包罗万象.果然,换了主力,大有不同. 微软今天还宣布开源其.NET框架,令.NET Core能在Linux和OS X上运 ...
- C#使用.net.mail配置163邮箱报错:不允许使用邮箱名称。 服务器响应为:authentication is required,smtp9,DcCowABHK4UYE11W2k6fAQ--.52196S2 1448940312
client.UseDefaultCredentials = true; 要放在 client.Credentials = new NetworkCredential("用户名", ...
- bzoj2154
#include<cstdio> #include<cstdlib> #include<iostream> #include<fstream> #inc ...
- bzoj1756 Vijos1083 小白逛公园
Description 小新经常陪小白去公园玩,也就是所谓的遛狗啦-在小新家附近有一条"公园路",路的一边从南到北依次排着n个公园,小白早就看花了眼,自己也不清楚该去哪些公园玩了. ...
- PHP null常量和null字节的区别
在学习isset()时,看到了这句话:“如果已经使用 unset() 释放了一个变量之后,它将不再是 isset().若使用 isset() 测试一个被设置成 NULL 的变量,将返回 FALSE.同 ...
- 用BFS和DFS解决圆盘状态搜索问题
人工智能课程的实验(我的解法其实更像是算法课程的实验) 用到的算法:深度优先搜索.宽度优先搜索(状态扩展的不同策略) 数据结构:表示状态的结构体.多维数组 (可能是最近做算法竞赛题的影响,这次并不像以 ...
- hdu 5392 Infoplane in Tina Town(数学)
Problem Description There is a big stone with smooth surface in Tina Town. When people go towards it ...
- Java IO :文件
在java应用程序中,文件是一种常用的数据源或者存储数据的媒介.所以这一小节将会对Java中文件的使用做一个简短的概述.这里只提供一些必要的知识点. 通过Java IO读文件 如果你需要在不同端之间读 ...
- [华为机试练习题]55.最大公约数 & 多个数的最大公约数
题目 描写叙述: 输入2个数字,最后输出2个数字的最大公约数 题目类别: 位运算 难度: 0基础 执行时间限制: 无限制 内存限制: 无限制 阶段: 入职前练习 输入: 2个整数 输出: 输出数字1和 ...