http://acm.hdu.edu.cn/showproblem.php?pid=1010

这题就是问能不能在t时刻走到门口,不能用bfs的原因大概是可能不一定是最短路路径吧。

但是这题要过除了细心外,还需要强力的剪枝。

奇偶性剪枝:参考 http://www.cppblog.com/Geek/archive/2010/04/26/113615.html

 #include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
char map[][];
int n,m,t,di,dj;
bool escape;
int dir[][]={{,-},{,},{,},{-,}};
void dfs(int si,int sj,int cnt)
{
if(cnt>) return;
if(escape) return;
if(si>n||sj>m||si<=||sj<=) return;
if(cnt==t&&si==di&&sj==dj) escape=;
if(escape) return;
if(cnt>=t) return;
int i,temp;
temp=(t-cnt)-abs(si-di)-abs(sj-dj);
if(temp<||temp&) return;
for(i=;i<;i++){
if(map[si+dir[i][]][sj+dir[i][]]!='X')
{
map[si+dir[i][]][sj+dir[i][]]='X';
dfs(si+dir[i][],sj+dir[i][],cnt+);
map[si+dir[i][]][sj+dir[i][]]='.';
}
}
return;
}
int main()
{
int i,j,si,sj;
while(cin>>n>>m>>t)
{
if(n==&&m==&&t==) break;
int wall=;
for(i=;i<=n;i++)
for(j=;j<=m;j++)
{
cin>>map[i][j];
if(map[i][j]=='S') { si=i; sj=j; }
else if(map[i][j]=='D') { di=i; dj=j; }
else if(map[i][j]=='X') wall++;
}
if(n*m-wall<=t)
{
cout<<"NO"<<endl;
continue;
}
escape=;
map[si][sj]='X';
dfs(si,sj,);
if(escape) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return ;
}

http://acm.hdu.edu.cn/showproblem.php?pid=1015

给定一个字符串和一个数n,然后再字符串中找出5个字符,满足题目中的等式并且字典序最大。

输入之后先把字符串从大到小排序,然后搜索即可。

 #include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; bool cmp(char a,char b)
{
return a>b;
} int k,j,flag,vis[];
char s[],ss[],res[]; bool judge(int v,int w,int x,int y,int z)
{
if(v-w*w+x*x*x-y*y*y*y+z*z*z*z*z==k)
return ;
return ;
} void dfs(int x)
{
if(flag) return;
int i;
if(x==)
{
if(judge(ss[]-,ss[]-,ss[]-,ss[]-,ss[]-)) {flag=;strcpy(res,ss);}
return;
}
int l=strlen(s);
for(i=;i<l;i++)
{
if(!vis[i])
{
vis[i]=;
ss[x]=s[i];
dfs(x+);
vis[i]=;
}
}
} int main()
{
int i;
//freopen("a.txt","r",stdin);
while(scanf("%d %s",&k,s)!=EOF&&k!=&&strcmp(s,"END")!=)
{
flag=;
sort(s,s+strlen(s),cmp);
memset(vis,,sizeof(vis));
dfs();
if(flag)
{
printf("%s\n",res);
}
else printf("no solution\n");
}
return ;
}

hdu - 1010 Tempter of the Bone (dfs+奇偶性剪枝) && hdu-1015 Safecracker(简单搜索)的更多相关文章

  1. HDU 1010 Tempter of the Bone(DFS+奇偶剪枝)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目大意: 输入 n m t,生成 n*m 矩阵,矩阵元素由 ‘.’ 'S' 'D' 'X' 四 ...

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

  3. hdu 1010 Tempter of the Bone (奇偶性剪枝)

    题意:有一副二维地图'S'为起点,'D'为终点,'.'是可以行走的,'X'是不能行走的.问能否只走T步从S走到D? 题解:最容易想到的就是DFS暴力搜索,,但是会超时...=_=... 所以,,要有其 ...

  4. HDU 1010 Tempter of the Bone --- DFS

    HDU 1010 题目大意:给定你起点S,和终点D,X为墙不可走,问你是否能在 T 时刻恰好到达终点D. 参考: 奇偶剪枝 奇偶剪枝简单解释: 在一个只能往X.Y方向走的方格上,从起点到终点的最短步数 ...

  5. hdu1010 Tempter of the Bone —— dfs+奇偶性剪枝

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 Tempter of the Bone Time Limit: 2000/1000 MS (Ja ...

  6. HDU 1010 Tempter of the Bone(深度+剪枝)

    http://acm.hdu.edu.cn/showproblem.php?pid=1010 题意:就是给出了一个迷宫,小狗必须经过指定的步数到达出口,并且每个格子只能走一次. 首先先来介绍一下奇偶性 ...

  7. hdu 1010 Tempter of the Bone 深搜+剪枝

    Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  8. (step4.3.1) hdu 1010(Tempter of the Bone——DFS)

    题目大意:输入三个整数N,M,T.在接下来的N行.M列会有一系列的字符.其中S表示起点,D表示终点. .表示路 . X表示墙...问狗能有在T秒时到达D.如果能输出YES, 否则输出NO 解题思路:D ...

  9. HDU 1010 Tempter of the Bone DFS(奇偶剪枝优化)

    需要剪枝否则会超时,然后就是基本的深搜了 #include<cstdio> #include<stdio.h> #include<cstdlib> #include ...

随机推荐

  1. 通过Log4j的DEBUG级别来显示mybatis的sql语句

        为了更加方便调试sql语句,需要显示mybatis的sql语句.     网络上的一般方式都是通过log4j来实现,但是很多都有问题.      经过实验,以下代码能够保持正常:(只显示myb ...

  2. 【BZOJ】【2756】【SCOI2012】奇怪的游戏

    网络流-最大流 这题……建模部分先略过 这道题是会卡时限的T_T俺的Dinic被卡了,在此放几篇很棒的讲网络流算法的文章,至于大家耳熟能详的论文就不放了…… http://www.cppblog.co ...

  3. Detecting diabetic retinopathy in eye images

    Detecting diabetic retinopathy in eye images The past almost four months I have been competing in a  ...

  4. Nginx使用webbench进行压力测试(转载)

    在运维工作中,压力测试是一项非常重要的工作.比如在一个网站上线之前,能承受多大访问量.在大访问量情况下性能怎样,这些数据指标好坏将会直接影响用户体验. 但是,在压力测试中存在一个共性,那就是压力测试的 ...

  5. HDOJ 1466 计算直线的交点数

    将n 条直线排成一个序列,直线2和直线1最多只有一个交点,直线3和直线1,2最多有两个交点,......,直线n 和其他n-1条直线最多有n-1个交点.由此得出n条直线互不平行且无三线共点的最多交点数 ...

  6. maven mirror repository

    简单点来说,repository就是个仓库.maven里有两种仓库,本地仓库和远程仓库.远程仓库相当于公共的仓库,大家都能看到.本地仓库是你本地的一个山寨版,只有你看的到,主要起缓存作用.当你向仓库请 ...

  7. 13test05:亲密数

    /*#include<iostream> using namespace std; int main() {int sum[3000]={0}; for(int i=1;i<3000 ...

  8. Razor语法学习

    原文:http://www.cnblogs.com/youring2/archive/2011/07/24/2115254.html 1.Razor的文件类型 Razor支持两种文件类型,分别是.cs ...

  9. 利用 NGINX 最大化 Python 性能,第一部分:Web 服务和缓存

    [编者按]本文主要介绍 nginx 的主要功能以及如何通过 NGINX 优化 Python 应用性能.本文系国内 ITOM 管理平台 OneAPM 编译呈现. Python 的著名之处在于使用简单方便 ...

  10. HDU2295 Radar (DLX)

    下面的代码99%参考了这个网站http://www.cnblogs.com/183zyz/archive/2011/08/07/2130193.html 人生的第一道DLX肯定是需要作一些参考的啦. ...