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. Extjs 选择元素涉及方法总结

    本文主要是解释Extjs在使用过程中使用的相关选择方法: 1.首先解释第一组概念: Ext.get(String/HTMLElement/Ext.Element el) Ext.getCmp(Stri ...

  2. hdu 3068 最长回文 manacher

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3068 给出一个只由小写英文字符a,b,c...y,z组成的字符串S,求S中最长回文串的长度.回文就是正 ...

  3. AVFoundation的使用

    AVFoundation的使用 2013-05-03 14:50:21|  分类: iphone_dev_note|举报|字号 订阅         相机相关应用一般会用到AVFoundation. ...

  4. Windows Server

    1. Windows Server 在试用license过期后会出现2小时一次的关机.如果暂时无法注册或者激活,下面的方法可以试试 taskkill /f /im wlms.exe ping -n 1 ...

  5. poj 3903 Stock Exchange(最长上升子序列,模版题)

    题目 #include<stdio.h> //最长上升子序列 nlogn //入口参数:数组名+数组长度,类型不限,结构体类型可以通过重载运算符实现 //数组下标从1号开始. int bs ...

  6. POJ 2891 Strange Way to Express Integers (解一元线性方程组)

    求解一元线性同余方程组: x=ri(mod ai) i=1,2,...,k 解一元线性同余方程组的一般步骤:先求出前两个的解,即:x=r1(mod a1)     1x=r2(mod a2)     ...

  7. POJ 2021

    #include <iostream> #include <string> #include <algorithm> #define MAXN 105 using ...

  8. Codeforces Round #259 (Div. 2) C - Little Pony and Expected Maximum (数学期望)

    题目链接 题意 : 一个m面的骰子,掷n次,问得到最大值的期望. 思路 : 数学期望,离散时的公式是E(X) = X1*p(X1) + X2*p(X2) + …… + Xn*p(Xn) p(xi)的是 ...

  9. http://my.oschina.net/u/719192/blog/506062?p={{page}}

    http://my.oschina.net/u/719192/blog/506062?p={{page}}

  10. MongoDB (五) MongoDB 数据库操作

    一.MongoDB创建数据库: use 命令 MongoDB use DATABASE_NAME 用于创建数据库.该命令将创建一个新的数据库,如果它不存在,否则将返回现有的数据库. 语法: use D ...