hdoj1010 Temperor of the bone
Tempter of the Bone
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 53106 Accepted Submission(s): 14281
doggie found a bone in an ancient maze, which fascinated him a lot.
However, when he picked it up, the maze began to shake, and the doggie
could feel the ground sinking. He realized that the bone was a trap, and
he tried desperately to get out of this maze.
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.
input consists of multiple test cases. The first line of each test case
contains three integers N, M, and T (1 < N, M < 7; 0 < T <
50), which denote the sizes of the maze and the time at which the door
will open, respectively. The next N lines give the maze layout, with
each line containing M characters. A character is one of the following:
'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<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
int fangxiang[][]={{-,},{,},{,-},{,}};
const int MAX=;
char map[MAX][MAX];
int mark[MAX][MAX];
int n,m,t;
int start_x,start_y;
int end_x,end_y;
using namespace std;
bool DFS(int x,int y,int step)
{
int i,a,b;
if(map[x][y]=='D' && step==t)
return true;
if(x<||x>n || y< || y>m)//判断到最后了,还没有找到
return false;
if(step>=t)//剪枝1:当step>=T时还没有找到D点
return false;
if(t-step<(abs(x-end_x)+abs(y-end_y)))//剪枝2:还需要的步数比理论上的最短距离还小
return false;
if((t-step-(abs(x-end_x)+abs(y-end_y)))%!=) //剪枝3:比理论上的最短距离多出来的必是偶数
return false;
for(i=;i<;i++)
{
a=x+fangxiang[i][];
b=y+fangxiang[i][];
if(a<=n && a>= && b>= && b<=m && map[a][b]!='X' && !mark[a][b]) //判断三个条件:1.检验_x,_y是否越界。2.看vis[][]是否访问过。3.看map[][]是否是墙
{
mark[a][b]=;
if(DFS(a,b,step+))
return true;
else
mark[a][b]=;
}
}
return false;
}
int main()
{
int i,j;
while(cin>>n>>m>>t && n+m+t)
{
memset(mark,,sizeof(mark));
for(i=;i<=n;i++)
{
for(j=;j<=m;j++)
{
cin>>map[i][j];
if(map[i][j]=='S')
{
start_x=i;
start_y=j;
}
if(map[i][j]=='D')
{
end_x=i;
end_y=j;
}
}
}
mark[start_x][start_y]=;
if(DFS(start_x,start_y,))
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return ;
}
hdoj1010 Temperor of the bone的更多相关文章
- HDOJ-1010 Tempter of the Bone(dfs+剪枝)
http://acm.hdu.edu.cn/showproblem.php?pid=1010 给出一个n*m的迷宫 X为墙 .为空地 S为起点 D为终点 给出时间T 每走一步花费一单位的时间 走过的空 ...
- 杭电1518 Square(构成正方形) 搜索
HDOJ1518 Square Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 玩儿转物联网IoT - 在Beagle Bone Black上运行node.js 程序
物联网(IoT)技术方兴未艾,智能手环,智能血压计,智能眼镜甚至智能鞋垫都开始进入我们的生活,各种智能设备层出不穷,世界已经到了一个"人有多大胆,地有多大产"的时代,不玩儿点物联网 ...
- Tempter of the Bone
Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he ...
- hdu 2602 Bone Collector(01背包)模板
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Ot ...
- hdu–2369 Bone Collector II(01背包变形题)
题意:求解01背包价值的第K优解. 分析: 基本思想是将每个状态都表示成有序队列,将状态转移方程中的max/min转化成有序队列的合并. 首先看01背包求最优解的状态转移方程:\[dp\left[ j ...
- 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 ...
- HDU 2602 Bone Collector WA谁来帮忙找找错
Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bone Collec ...
- Bone Collector(01背包)
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87125#problem/N 题目: Description Many year ...
随机推荐
- 伪造A标签跳转(非window.open)Jquery
尊重原创:http://blog.csdn.net/zdb330906531
- SQL Server表描述 及 字段描述的增、删、改、查询
SQL Server表描述 及 字段描述的增.删.改.查询 --测试: --创建表及描述信息 ),isname )) --为表添加描述信息 EXECUTE sp_addextendedproperty ...
- 23、java 通过System.getProperties()获取系统参数
1.java的System.getProperty()方法可以获取的值 java.version Java 运行时环境版本 java.vendor Java 运行时环境供应商 java.vendor. ...
- php 5.3 垃圾回收
1.引用计数器 php中的每个变量都存在一个zval的变量容器中, zval容易包括变量类型.值.is_ref(是否是引用).refercount(引用次数,也成为符号), 所有的符号存在一个符号表中 ...
- Linux服务器修改时区时间
时间的一致性很关键,对于日志的分析和程序的对接都至关重要! 01.tzselect 修改时区 可以使用命令 tzselect,修改时区.操作示例: $ tzselect Please identify ...
- CentOS下安装IDE -- QTCreator
月底,美国的大佬们将会过来给我们几个搞一个培训.老大要求我们提前学习一下Qt. 我现在的首要任务是在自己的CentOS系统上安装一下Qt开发环境. 1. 获取下载地址 Qt的官网是:http://qt ...
- 二分查找法的C++泛型实现
算法非常easy,直接贴代码啦 #include <iostream> using namespace std; template<typename T> int binary ...
- HDUOJ-----2066一个人的旅行
一个人的旅行 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- HDUOJ----(1175)连连看
连连看 Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- sigmoid 函数与 softmax 函数
sigmoid 函数与 softmax 函数 1. sigmoid 函数 sigmoid 函数又称:logistic函数,逻辑斯谛函数.其几何形状即为一条sigmoid曲线. lo ...