杭电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 & % ...
随机推荐
- kibana 访问IP分布图
- 解决SQL server不支持utf8,php却用utf8的矛盾问题
function convert2utf8($string) { return iconv("gbk","utf-8",$string); } function ...
- 用特殊字体来实现矢量ICON
用特殊字体来实现矢量ICON tips:其实每个icon都是一个unicode字符,所以,可以通过改变font-size实现icon的矢量放大:可以通过改变color实现多色系.
- iOS AFNetworking 详解
1. 很不错的介绍 http://m.blog.csdn.net/blog/jackljf/38736625
- 恢复Linux下被误删除的文件(笔记)
恢复Linux下被误删除的文件 [root@xuegod63 ~]# mount /dev/cdrom /mnt/ 分一个区:sda4 查找:extundelete 分一个区:sda4 [root ...
- array模块
array模块定义了一种序列数据结构,看起来和list很相似,但是所有成员必须是相同基本类型. 2.1 array-固定类型数据序列 array作用是高效管理固定类型数值数据的序列. 2.2.1 初始 ...
- IOS UIImage 模糊
#import <UIKit/UIKit.h> #import <Accelerate/Accelerate.h> #import <QuartzCore/QuartzC ...
- Guice 学习(六)使用Provider注入服务( Provider Inject Service)
1.定义接口 package com.guice.providerInject; import com.google.inject.ProvidedBy; public interface Servi ...
- 在Unity3d编辑器中加入菜单以及菜单项
在引用UZGUI插件时,u3d编辑器的菜单条发生了变化,新增了菜单和菜单项,于是乎自己也像尝试一下,看了EZGUI的About_EZ_GUI脚本文件后,结果大出我所料,原来SO EASY! using ...
- ORACLE数据库常用查询二
ORACLE数据库常用查询 1.查看表空间对应数据文件情况: SQL MB,AUTOEXTENSIBLE FROM DBA_DATA_FILES; TABLESPACE_NAME FILE_NAME ...