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. 【转载】Sencha Touch 提高篇 组件选择器

    免责声明:     本文转自网络文章,转载此文章仅为个人收藏,分享知识,如有侵权,请联系博主进行删除.     原文作者:威老     原文地址:http://www.cnblogs.com/weil ...

  2. JRebel: ERROR Could not define reloadable class 'com.sun.proxy.$Proxy118': java.lang.OutOfMemoryError: PermGen space

    MyEclipse由于配置了JRebel,所以是它报错,不过根本问题还是:java.lang.OutOfMemoryError: PermGen space 现在按照经验调整内存大小. 在MyEcli ...

  3. 2014ACM/ICPC亚洲区北京站 上交命题

    A http://acm.hdu.edu.cn/showproblem.php?pid=5112 输入n个时刻和位置,问那两个时刻间速度最快. 解法:按照时间排序,然后依次求相邻两个之间的速度,速度= ...

  4. apple开发者账号申请

    1.  登陆appleID. 2. 进入 Your Account 3. 在Account Summary 中的MemberShips中选择第一个(界面大概如下) 4.选择后进入下图. 5. yes ...

  5. 2-Highcharts 3D图之3D柱状图带可调试倾斜角度

    <!DOCTYPE> <html lang='en'> <head> <title>2-Highcharts 3D图之3D柱状图带可调试倾斜角度< ...

  6. TJU 4087. box

    题目:Tuhao and his two small partners participated in the tournament.But in the end, they lost the cha ...

  7. ubuntu第一次设置root密码

    安装ubuntu时,系统让用户创建了一个非root用户,系统启动后使用这个用户,在需要执行超级用户权限的指令时,可以通过sudo来执行.为此我们可以通过这样的方式修改root的密码:dengfei@d ...

  8. volatile 关键字的复习

    今天早上看何登成的微博(http://hedengcheng.com/?p=725) 对volatile 关键字语意进行了深入分析. 看完之后,用自己的话总结如下: 1.c/c++ volatile中 ...

  9. MongoDB (十一) MongoDB 排序文档

    sort() 方法 要在 MongoDB 中的文档进行排序,需要使用sort()方法. sort() 方法接受一个文档,其中包含的字段列表连同他们的排序顺序.要指定排序顺序1和-1. 1用于升序排列, ...

  10. 博弈的SG函数理解及模板

    首先定义mex(minimal excludant)运算,这是施加于一个集合的运算,表示最小的不属于这个集合的非负整数.例如mex{0,1,2,4}=3.mex{2,3,5}=0.mex{}=0. 对 ...