博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 1010 Tempter of the Bone 奇偶剪枝
阅读量:5059 次
发布时间:2019-06-12

本文共 2868 字,大约阅读时间需要 9 分钟。

 
  1. 如果所给的时间(步数) t 小于最短步数path,那么一定走不到。
  2. 若满足t>path。但是如果能在恰好 t 步的时候,走到出口处。那么(t-path)必须是二的倍数。

关于第二种方案的解释:

这种方案学名为“奇偶剪枝”。我们已知了最短的步数就是直角三角形的两条直角边,实际上的路径却不一定非要沿着这两条边走的。仔细看看只要是移动方向一直是右、下,那么走到的时候总步数也一定是path的。然而由于墙的存在或许我们不可能一直右、下的走下去。为了避开墙,我们可能会向左走,向上走等等。但为了到达目的地,你在最短步数的基础上,如果向右走了一步,那么某一时候也必须再向左走一步来弥补。所以(t-path)一定要是2的倍数。

C - Tempter of the Bone
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
Submit     

Description

The 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

The 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. 
 

Output

For each test case, print in one line "YES" if the doggie can survive, or "NO" otherwise. 
 

Sample Input

4 4 5 S.X. ..X. ..XD .... 3 4 5 S.X. ..X. ...D 0 0 0
 

Sample Output

NO YES
 
#include
#include
using namespace std;bool vis[8][8];struct Node{ int x,y; int step;} node[8][8];int n,m,t;char ma[8][8];int dx[]= {
0,0,1,-1};int dy[]= {
1,-1,0,0};bool dfs(int x,int y){ if(ma[x][y]=='S') { node[x][y].step=0; } if(ma[x][y]=='D') { if(node[x][y].step==t) return true; else return false; } for(int i=0; i<4; i++) { int nx=dx[i]+x; int ny=dy[i]+y; if((!vis[nx][ny])&&(nx>=0&&ny>=0)&&(nx
t||(t-abs(ex-x)-abs(ey-y))%2==1) { printf("NO\n"); continue; } if(dfs(x,y)) printf("YES\n"); else printf("NO\n"); } return 0;}

 

转载于:https://www.cnblogs.com/superxuezhazha/p/5714112.html

你可能感兴趣的文章
Javascript 数组相关操作
查看>>
选择排序
查看>>
codevs 5462 HYY迎亲I
查看>>
类模板成员函数
查看>>
Dubbo
查看>>
并发计算/并行计算/串行计算/分布式计算 概念简述
查看>>
c#邮件发送
查看>>
debuggee python
查看>>
redis 从入门到遗忘
查看>>
构建之法阅读笔记02
查看>>
最简单实用的seo知识
查看>>
使用jmeter 进行http 接口测试
查看>>
编号001:deque用法暂时总结
查看>>
关于在Android中Activity页面跳转的方法
查看>>
GDAL数据模型
查看>>
[Python 网络编程] TCP编程/群聊服务端 (二)
查看>>
【洛谷】P1541 乌龟棋(四维背包dp)
查看>>
Chapter 7 Bond Basics
查看>>
[转载] 笑话:Developer and product manager
查看>>
排序算法之堆排序
查看>>