Tempter of the Bone
Description
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
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.
Output
Sample Input
S.X.
..X.
..XD
....
3 4 5
S.X.
..X.
...D
0 0 0
Sample Output
YES
题目意思很简单,但是有一个很坑的地方。就是给你一个地图,.表示可以走,X不可以走,S起点,D终点,然后给你一个步数num,然后坑点来了,问的是能不能恰好在num步的时候到达终点,步数一定要等于num。
当然,这道题,如果你直接DFS肯定是会错的。需要剪枝。
这里只要奇偶剪枝就好。
//Asimple
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
const int maxn = ;
int dx[] = {-,,,}, dy[]={,,-,};
typedef long long ll;
int n, m, num, T, k, x, y;
int endx, endy;
char Map[maxn][maxn];
bool vis[maxn][maxn], flag; bool wrang(int x, int y) {
return x< || x>=n || y< || y>=m || Map[x][y] == 'X';
} void DFS(int x, int y, int step) {
if( Map[x][y] == 'D' ) {
if( step == num ) {
flag = true;
return ;
}
return ;
}
int as = abs(x-endx)+abs(y-endy);
//奇偶剪枝
if( (num-as-step)% || as+step>num) return;
if( flag ) return ;
for(int i=; i<; i++) {
int nx = x+dx[i];
int ny = y+dy[i];
if( !wrang(nx, ny) && !vis[nx][ny] ) {
vis[nx][ny] = true;
DFS(nx, ny, ++step);
//回溯
vis[nx][ny] = false;
step--;
}
}
} void input() {
while( cin >> n >> m >> num && ( n + m + num ) ) {
for(int i=; i<n; i++) {
cin >> Map[i];
for(int j=; j<m; j++) {
if( Map[i][j] == 'S' ) {
x = i;
y = j;
}
if( Map[i][j] == 'D' ) {
endx = i;
endy = j;
}
vis[i][j] = false;
}
}
flag = false;
vis[x][y] = true;
int as = abs(endx-x)+abs(endy-y);
//奇偶剪枝
if( ( as + num )&) {
cout << "NO" << endl;
continue;
}
DFS(x,y,);
if( flag ) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
} int main(){
input();
return ;
}
Tempter of the Bone的更多相关文章
- 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 ...
- 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
HDU 1010 题目大意:给定你起点S,和终点D,X为墙不可走,问你是否能在 T 时刻恰好到达终点D. 参考: 奇偶剪枝 奇偶剪枝简单解释: 在一个只能往X.Y方向走的方格上,从起点到终点的最短步数 ...
- 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 ...
- hdoj 1010 Tempter of the Bone【dfs查找能否在规定步数时从起点到达终点】【奇偶剪枝】
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- 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 深搜+剪枝
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- 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(条件迷宫DFS,HDU1010)
题意 一仅仅狗要逃离迷宫 能够往上下左右4个方向走 每走一步耗时1s 每一个格子仅仅能走一次且迷宫的门仅仅在t时刻打开一次 问狗是否有可能逃离这个迷宫 直接DFS 直道找到满足条件的路径 ...
随机推荐
- Approaches to Vector Computation
COMPUTER OR GANIZATION AND ARCHITECTURE DESIGNING FOR PERFORMANCE NINTH EDITION
- Spring 000 框架简介 (转载)
转载自:https://my.oschina.net/myriads/blog/37922 1.使用框架的意义与Spring的主要内容 随着软件结构的日益庞大,软件模块化趋势出现,软件开发也需要多人合 ...
- SQL INSERT INTO 语句
SQL Order By SQL update INSERT INTO 语句 INSERT INTO 语句用于向表格中插入新的行. 语法 INSERT INTO 表名称 VALUES (值1, 值2, ...
- 带你玩转JavaWeb开发之六-mysql基本语法详解及实例(3)
[语法] update 表名 set 列名=列值,列名=列值 -[条件]; [注意事项] * 修改的列的值需要与列的类型一致. * 修改的列的值的长度不能超过列的类型的最大长度. * 字符串类型和日期 ...
- c语言文法简化版文法
<源程序>→<外部声明>|<外部声明><函数体> <外部申明>→<头文件><函数声明>|其他声明 <函数体&g ...
- 转摘 MySQL扫盲篇
一下文章摘自:http://www.jellythink.com/archives/636 MySQL扫盲篇 2014-09-15 分类:MySQL / 数据库 阅读(1412) 评论(1) 为什么 ...
- Json与常见的类型之间的转换
常用的json list转json List list=new ArrayList(); list.add("1"); list.add("2"); JsonA ...
- Wrestling Match---hdu5971(2016CCPC大连 染色法判断是否是二分图)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5971 题意:有n个人,编号为1-n, 已知X个人是good,Y个人是bad,m场比赛,每场比赛都有一个 ...
- Resharper 8.2 注册码
用户名:ronle注册码:ZoJzmeVBoAv9Sskw76emgksMMFiLn4NM
- 采用阿里的API进行动态域名解析
#!/usr/bin/env python # -*- coding:utf-8 -*- import os from aliyunsdkcore import client from aliyuns ...