杭电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 & % ...
随机推荐
- mysql 的 decimal类型
最近做项目时将decimal定义成了decimal(5,2),然后等到最大的结果都是999.99,找了很多地方找不出bug在哪里插入很更新的数据都是正确的而结果却都是999.99,最后才知道decim ...
- bzoj1060 [ZJOI2007]时态同步
Description 小Q在电子工艺实习课上学习焊接电路板.一块电路板由若干个元件组成,我们不妨称之为节点,并将其用数字1,2,3….进行标号.电路板的各个节点由若干不相交的导线相连接,且对于电路板 ...
- MySQL存储过程事务处理
BEGIN ; ; START TRANSACTION; #这边放sql语句,涉及到的表必须都为InnoDB THEN ROLLBACK; ELSE COMMIT; END IF; END 转自:ht ...
- poj 2411 Mondriaan's Dream_状态压缩dp
题意:给我们1*2的骨牌,问我们一个n*m的棋盘有多少种放满的方案. 思路: 状态压缩不懂看,http://blog.csdn.net/neng18/article/details/18425765 ...
- SharePoint excel service web part 连接到 filter web part
本文讲述SharePoint excel service web part 连接到 filter web part的一个简单应用场景. SharePoint excel service web par ...
- UGUI 过渡动画插件,模仿NGUI的Tween (转载)
最近在相亲,后来好朋友跟我说他写了一个好插件,于是我就把女朋友甩了,看看他的插件,可以在UGUI制作简单过渡动画. 我看了下是模仿NGUI的Tween, 我在筱程的基础上稍微改到人性化, 简单支持的让 ...
- Atitit.软件guibuttonand面板---os区-----linux windows搜索文件 目录
Atitit.软件guibuttonand面板---os区-----搜索文件 1. Find 1 2. 寻找文件夹 1 3. 2. Locate// everything 1 4. 3. Wherei ...
- Linux系统守护进程详解ntsysv 可以关掉那些服务
acpid, haldaemon, messagebus, klogd,network, syslogd 以上几个服务必须开启!其他的分析如下: 1.NetworkManager,NetworkMa ...
- 网页http请求的整个过程
这几天看一个讲解一个网页从我们输入地址到显示在我们面前的一个讲解,是我对http又有了一个完整的了解,现在做一下整个流程的记录,虽然不是很详细,但是整个过程是完整的.如果不对,请指正! 打开浏览器,地 ...
- SQLLoader4(数据文件中的列与表中列不一致情况-filler)
A.数据文件中字段个数少于表中列字段个数,但数据文件中缺少的列,在表定义中可以为空.----- 这种情况是比较简单的,只需要将数据文件中数据对应的列的名字写到控制文件中即可.因为SQL*Loader是 ...