HDU 1010 Tempter of the Bone 骨头诱惑(DFS+剪枝)
题意:
必须在第t秒走到格子D上,S为起点,D为终点,点就是可以走,X就是墙。
思路:
将迷宫外围四面都筑墙‘X’。深度搜索+奇偶剪枝,再加一个剪枝“无法在指定时间内到达”。
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
using namespace std;
vector<string> v;
int n,m;
int x_1,y_1,x_2,y_2;
bool maze(int x,int y,int t) //目前走到第n行m列的位置
{
if(t==) //若t小于0,则检查四个方向是否有门D
{
if(x_2==x && (y_2==y-||y_2==y+))
return true;
if(y_2==y && (x_2==x-||x_2==x+))
return true;
}
else //若不为0,调用4次此函数,分别是四个方向,若该方向不能走,则不调用
{
t--;
v[x][y]=''; //封掉该格子
if(v[x-][y]=='.' && maze(x-,y,t)==true )
return true;
if(v[x+][y]=='.' && maze(x+,y,t)==true )
return true;
if(v[x][y-]=='.' && maze(x,y-,t)==true )
return true;
if(v[x][y+]=='.' && maze(x,y+,t)==true )
return true;
}
v[x][y]='.'; //开放该格子
return false;
}
int main()
{
int t,i,j; //x为行,y为列。
string temp="",tem="XXXXXXXX";
while(scanf("%d %d %d",&n,&m,&t)&&n!=)
{
v.push_back(tem);
for(i=;i<n;i++)
{
cin>>temp;
temp='X'+temp;
temp+='X'; //围起来
v.push_back(temp);
if(temp.find('S')!=-)
{
x_1=i+;y_1=temp.find('S');
}
if(temp.find('D')!=-)
{
x_2=i+;y_2=temp.find('D');
}
}
v.push_back(tem); if( abs(y_2-y_1)+abs(x_2-x_1)>t)
printf("NO\n");
else if( (abs(y_2-y_1)+abs(x_2-x_1))%!=t% )
printf("NO\n");
else if(maze(x_1,y_1,t)==true)
printf("YES\n");
else
printf("NO\n");
v.clear();
}
return ;
}
1010
题目直译:
小狗在一个古老的迷宫里发现一根骨头,迷宫让它很惊讶。但是,当他拿起骨头,迷宫开始振动,而小狗能够感觉到地面在下沉。
它意识到骨头是个陷阱,他准备分身一试逃出迷宫。
迷宫是个矩形,其大小是N*M,有个门在迷宫里。在一开始,门是关的,它将会在第T秒开一小段时间(小于1秒)。
因此,小狗必须在刚好T秒时到达门的旁边。每一秒,小狗能够移动一步到当前块块的上、下、左、右的块。
一旦它进入一个块,这块的地面将开始下沉并消失在下一秒(即每个位置只能走一次)。它不能够呆在一个块上超过1秒,也不能进入一个已走过过的块。
这只小狗能活下去吗?请帮助他。
输入:第一行包括3个整数N、M、T,分别代表迷宫的大小、迷宫门会开的时刻。
接下来N行是迷宫的布局,每行包括M个字符,只能是以下四种之一:
X:一面墙,不能进入
S:狗的起点
D:迷宫门
.:一个空块。
1<N
M<7
0 < T < 50
HDU 1010 Tempter of the Bone 骨头诱惑(DFS+剪枝)的更多相关文章
- HDU 1010 Tempter of the Bone (ZOJ 2110) DFS+剪枝
传送门: HDU:http://acm.hdu.edu.cn/showproblem.php?pid=1010 ZOJ:http://acm.zju.edu.cn/onlinejudge/showPr ...
- HDU 1010 Tempter of the Bone --- DFS
HDU 1010 题目大意:给定你起点S,和终点D,X为墙不可走,问你是否能在 T 时刻恰好到达终点D. 参考: 奇偶剪枝 奇偶剪枝简单解释: 在一个只能往X.Y方向走的方格上,从起点到终点的最短步数 ...
- 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 1010 Tempter of the Bone 奇偶剪枝
如果所给的时间(步数) t 小于最短步数path,那么一定走不到. 若满足t>path.但是如果能在恰好 t 步的时候,走到出口处.那么(t-path)必须是二的倍数. 关于第二种方案的解释 ...
- 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 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 1010 Tempter of the Bone 分类: Translation Mode 2014-08-04 16:11 82人阅读 评论(0) 收藏
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- hdu 1010 Tempter of the Bone 深搜+剪枝
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- 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 ...
随机推荐
- redis系列:通过通讯录案例学习hash命令
前言 这一篇文章将讲述Redis中的hash类型命令,同样也是通过demo来讲述,其他部分这里就不在赘述了. 项目Github地址:https://github.com/rainbowda/learn ...
- sql server 中raiserror的使用
server数据库中raiserror的作用就和asp.net中的throw new Exception一样,用于抛出一个异常或错误.这个错误可以被程序捕捉到. raiserror('错误的描述',错 ...
- Educational Codeforces Round 52F(树形DP,VECTOR)
#include<bits/stdc++.h>using namespace std;int n,k;vector<int>son[1000007];int dp[100000 ...
- 【转】C# 使用正则表达式去掉字符串中的数字,或者去掉字符串中的非数字
源地址:http://www.cnblogs.com/94cool/p/4332957.html
- cf873F(xjb+二分)
题目链接:http://codeforces.com/problemset/problem/837/F 题意:给出一个大小为 n 的数组 a 和一个数 k,每次操作后的到一个 a' 数组,a'i 为 ...
- 让你的spring-boot应用日志随心所欲--spring boot日志深入分析
1.spring boot日志概述 spring boot使用Commons Logging作为内部的日志系统,并且给Java Util Logging,Log4J2以及Logback都提供了默认的配 ...
- 退役or延期退役
究竟是\(150\)天后退役,还是能继续续命呢? 一切看自己了!加油!\(cyh\)!千万不要败在别人的只言片语之下啊!
- CF616D Longest k-Good Segment
题目描述 给定一个包含\(n\)个整数的序列\(a\),\(0\le a_i \le 10^6\),询问不重复数字个数\(\le k\)的最长区间的左右端点.如果有多解输出任意一组. 输入输出格式 输 ...
- 华东交通大学2017年ACM“双基”程序设计竞赛 1010
Problem Description 定义操作:将数 n 变为 f(n) = floor(sqrt(n)).即对一个数开平方后,再向下取整.如对 2 进行一次操作,开平方再向下取整, 1.41421 ...
- mycat1.6.5分片(字符串拆分hash)
https://blog.csdn.net/webnum/article/details/78313525 分片规则:字符串拆分hash 一.conf/schema.xml文件 <?xm ...