Hdu1010Tempter of the Bone 深搜+剪枝
题意:输入x,y,t.以及一个x行y列的地图,起点‘S’终点‘D’地板‘.’墙壁‘X’;判断能否从S正好走t步到D。
题解:dfs,奇偶性减枝,剩余步数剪枝。
ps:帮室友Debug的题:打错了两个字母。题目看错。没有初始化map。orz ...不过我dfs也不熟,更别说剪枝了。
//#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>
#include <algorithm>
using namespace std;
#define LL long long
int n, m, T;
int si, sj, ei, ej;
char a[][];
int map[][];
int dir[][] = { { , },{ -, },{ , },{ ,- } };
int check(int i, int j, int t) {
if (i< || i >= n || j< || j >= m || map[i][j] || a[i][j] == 'X') return false; return true;
}
bool dfs(int i, int j, int t) { if (i == ei&&j == ej&&t==T) return true;
if (t>=T) return false;
map[i][j] = ;
for (int k = ; k<; k++) {
int di = i + dir[k][];
int dj = j + dir[k][];
if (!check(di, dj, t + )) continue;
if (dfs(di, dj, t + ))
return true;
map[di][dj] = ;
}
return false;
}
int main() {
while (~scanf("%d%d%d", &n, &m, &T)) {
if (n == && m == && T == ) break;
memset(map, , sizeof(map));
for (int i = ; i<n; i++)
scanf("%s", a[i]);
int ok = ;
for (int i = ; i<n; i++) {
for (int j = ; j<m; j++) {
if (a[i][j] == 'D') {
ei = i; ej = j;
ok++;
}
if (a[i][j] == 'S') {
si = i; sj = j;
ok++;
}
if (ok == ) break;
}
if (ok == ) break;
}
if ((T - (abs(ei - si) + abs(ej - sj))) % || (T - (abs(ei - si) + abs(ej - sj)))<) printf("NO\n");
else if (dfs(si, sj,)) printf("YES\n");
else printf("NO\n");
}
return ;
}
Hdu1010Tempter of the Bone 深搜+剪枝的更多相关文章
- hdu 1010 Tempter of the Bone 深搜+剪枝
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- HDU 1010 Temper of the bone(深搜+剪枝)
Tempter of the Bone Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) ...
- hdu1010 Tempter of the Bone(深搜+剪枝问题)
Tempter of the Bone Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission( ...
- Hdu3812-Sea Sky(深搜+剪枝)
Sea and Sky are the most favorite things of iSea, even when he was a small child. Suzi once wrote: ...
- poj1190 生日蛋糕(深搜+剪枝)
题目链接:poj1190 生日蛋糕 解题思路: 深搜,枚举:每一层可能的高度和半径 确定搜索范围:底层蛋糕的最大可能半径和最大可能高度 搜索顺序:从底层往上搭蛋糕,在同一层尝试时,半径和高度都是从大到 ...
- UVA 10160 Servicing Stations(深搜 + 剪枝)
Problem D: Servicing stations A company offers personal computers for sale in N towns (3 <= N < ...
- ACM 海贼王之伟大航路(深搜剪枝)
"我是要成为海贼王的男人!" 路飞他们伟大航路行程的起点是罗格镇,终点是拉夫德鲁(那里藏匿着"唯一的大秘宝"--ONE PIECE).而航程中间,则是各式各样的 ...
- hdu 1518 Square(深搜+剪枝)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1518 题目大意:根据题目所给的几条边,来判断是否能构成正方形,一个很好的深搜应用,注意剪枝,以防超时! ...
- POJ-1724 深搜剪枝
这道题目如果数据很小的话.我们通过这个dfs就可以完成深搜: void dfs(int s) { if (s==N) { minLen=min(minLen,totalLen); return ; } ...
随机推荐
- ckeditor4.4.6添加代码高亮
研究了很久才发现,在 ckeditor4.4.6中添加代码高亮超级简单啊,下面直接上过程 ckeditor4.4.6支持自定义代码高亮,利用Code Snippet插件并默认启用highlight.j ...
- 在oracle配置mysql数据库的dblink
本文介绍如何在oracle配置mysql数据库的dblink:虽然dblink使用很占资源:俗称“性能杀手”.但有些场景不得不使用它.例如公司使用数据库是oracle:可能其他部门或者CP合作公司使用 ...
- 给sharepoint某列表项单独赋予权限
/// <summary> /// 列表项事件 /// </summary> public class EventReceiver2 : SPItemEventReceiver ...
- Ruby Tutorial
http://www.tutorialspoint.com/ruby/ruby_quick_guide.htm http://www.cnblogs.com/PurpleCow/archive/201 ...
- java jni调用
http://www.cnblogs.com/mandroid/archive/2011/06/15/2081093.html
- [Ubuntu] arp-scan - 扫描网络设备
使用arp-scan扫描所有网络设备信息. 1. 安装arp-scan ifantastic@ubuntu:~$ sudo apt-get install arp-scan 2. 扫描网络所有设备 i ...
- 【摘抄】C++程序员练级攻略
摘抄自互联网文章 作为C++程序员,或者说程序员一定要提升自己: 专访李运华:程序员如何在技术上提升自己-CSDN.NET专访徐宜生:坚决不做代码搬运工!-CSDN.NET 上面两个文章我觉得都不错. ...
- php_admin_value open_basedir 引起的上传文件失败解决方法
为了安全,我们通常会在虚拟主机设置中,加入这一行php_admin_value open_basedir "/usr/local/apache/htdocs/www"但这会导致mo ...
- 【Spring Boot && Spring Cloud系列】Spring Boot的启动器Starter
Spring Boot的内置Servlet Container: Name Servlet Version Java Version Tomcat8 3.1 Java 7+ Tomcat7 3.0 J ...
- 【大数据系列】hadoop集群设置官方文档翻译
Hadoop Cluster Setup Purpose Prerequisites Installation Configuring Hadoop in Non-Secure Mode Config ...