杭电1010(dfs + 奇偶剪枝)
题目:
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.
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.
doggie can survive, or "NO" otherwise.
#include<stdio.h>
#include<string.h> int t, flag, startx, starty, endx, endy, cout, visit[][], xx[] = {, -, , }, yy[] = {-, , , };
char a[][]; int dfs(){
int i;
visit[startx][starty] = ;
if(cout == t){
if(startx == endx && starty == endy){
printf("YES\n");
flag = ;
}
return ;
}
for(i = ; i < && flag; i ++){
startx += xx[i];
starty += yy[i];
if(visit[startx][starty] == ){
if(a[startx][starty] != 'X'){
//visit[startx][starty] = 0;
cout ++;
dfs();
visit[startx][starty] = ;//不行后,都要标志成未经过,因为下一个遍历可能遍历到;
cout --; }
startx -= xx[i];
starty -= yy[i];//这两句是当dfs返回后,将x,y变成上一个的值;
}
else{
startx -= xx[i];
starty -= yy[i];
} }
return ;
} int main(){
int n, m, i, j;
while(scanf("%d %d %d", &n, &m, &t) && (n || m || t)){
getchar();
cout = ;
flag = ;
memset(visit, , sizeof(visit));
for(i = ; i <= n; i ++){
for(j = ; j <= m; j ++){
scanf("%c", &a[i][j]);
visit[i][j] = ;
if(a[i][j] == 'S'){
startx = i;
starty = j;
}
else if(a[i][j] == 'D'){
endx = i;
endy = j;
}
}
getchar();
}
//getchar();
if((startx + starty + endx + endy) % ==){
if(t % != ){
printf("NO\n");
continue;
}
}
else{
if(t % == ){
printf("NO\n");
continue;
}
}
dfs();
if(flag == ){
printf("NO\n");
}
}
return ;
}
奋进
杭电1010(dfs + 奇偶剪枝)的更多相关文章
- hdoj--1010<dfs+奇偶剪枝>
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目描述:在n*m的矩阵中,有一起点和终点,中间有墙,给出起点终点和墙,并给出步数,在该步数情况 ...
- HDU 1010 Tempter of the Bone(DFS+奇偶剪枝)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目大意: 输入 n m t,生成 n*m 矩阵,矩阵元素由 ‘.’ 'S' 'D' 'X' 四 ...
- 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(DFS+奇偶剪枝+回溯)
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- hdu1010Tempter of the Bone(dfs+奇偶剪枝)
题目链接:pid=1010">点击打开链接 题目描写叙述:给定一个迷宫,给一个起点和一个终点.问是否能恰好经过T步到达终点?每一个格子不能反复走 解题思路:dfs+剪枝 剪枝1:奇偶剪 ...
- 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 ...
- M - Tempter of the Bone(DFS,奇偶剪枝)
M - Tempter of the Bone Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
随机推荐
- 解决SQL server不支持utf8,php却用utf8的矛盾问题
function convert2utf8($string) { return iconv("gbk","utf-8",$string); } function ...
- Linux服务器挂死案例分析
问题现象: 在linux服务器上运行一个指定的脚本时,就会出现无数个相同进程的,而且不停的产生,杀也杀不掉,最后系统就陷入死循环,无法登陆,只能人工去按机器的电源键才可以.这够崩溃的吧? 问题分析过程 ...
- JS帮你计算属相
背景:一个人出生在2014年的正月初一,他的生肖到底是属蛇还是属马呢?这就要确定那一天才是一年的开始.是春节还是立春?每年的春节是正月初一,但是生肖必须是从立春日开始计算.春节是1912年孙中 ...
- IOS 判断设备类型
- (NSString*)deviceString { // 需要#import "sys/utsname.h" struct utsname systemInfo; uname( ...
- Javascript 中的变量
var a; console.log("The value of a is " + a); // The value of a is undefined console.log(& ...
- chart.js制作折线图
<!DOCTYPE html> <html> <head> <title></title> </head> <script ...
- EffectiveC#03--用委托表示回调,用事件定义对外接口
1.回调的场景:我给了儿子一个任务且他可以报告状态来(重复的)打断我.而我在等待他完成任务的每一个部份时不用阻塞我自己的进程.他可以在有重要(或者事件)状态报告时,可以定时的打断我,或者向我询求帮助 ...
- Centos6架设GIT服务,windows客户端使用TortoiseGit加载KEYGEN连接GIT服务器
前几天得空,想起前一阵学了GIT还没好好实践,就在虚拟机中安装测试了一下,并简单记录了CENTOS6中GIT安装,ssh-keygen生成,客户端使用TortoiseGit加载KEYGEN连接GIT服 ...
- UINavigationController 导航控制器
一.导航视图控制器 1.管理视图控制器 2.控制视图控制器之间的跳转 3.是以压栈和出栈的形式来管理视图控制器 4.导航视图控制器必须要设置根视图控制器 5.导航是视图控制器包含UINavigatio ...
- JS闭包(一)
闭包是指有权访问另一个函数作用域中的变量的函数. 创建闭包的常见方法:在一个函数内部创建另一个函数. 对彻底理解闭包,需要知道如何创建作用域链以及作用域链有什么作用的细节. 闭包的功能: 保存函数执行 ...