深度搜索:棋盘问题,详见http://poj.org/problem?id=1321

//#include<bits/stdc++.h>

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
using namespace std;
#define INF 0x3f3f3f3f
typedef long long ll;
char a[10][10];
int vis[10];
int n,k;
int ans,now;
void DFS(int m)
{
if(now==k){
ans++;
return ;
}
if(m==n)
return ;
for(int i=0;i<n;i++){
if(!vis[i]&&a[m][i]=='#')
{
vis[i]=1;
now++;
DFS(m+1);
vis[i]=0;
now--; } }
DFS(m+1);
}
int main()
{
while(scanf("%d%d",&n,&k)&&n!=-1&&k!=-1)
{
memset(vis,0,sizeof(vis));
for(int i=0;i<n;i++)
scanf("%s",a[i]);
ans=now=0;
DFS(0);
printf("%d\n",ans);
}
}

 

BFS题目:Dungeon Master  (POJ2251: http://poj.org/problem?id=2251)

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
using namespace std;
#define INF 0x3f3f3f3f
typedef long long ll;
int L,R,C;
char Map[][][];
int vis[][][];
int to[][]={,,,,,-,,,,,-,,,,,-,,};
int sx,sy,sz,ex,ey,ez;
int ans;
struct node{
int x;
int y;
int z;
int step;
};
int check(int x,int y,int z)
{
if(x<||y<||z<||x>=L||y>=R||z>=C)
return ;
else if(Map[x][y][z]=='#')
return ;
else if(vis[x][y][z]==)
return ;
return ;
}
int bfs()
{
queue<node> q;
node temp,next;
while(!q.empty())
{
q.pop();
}
temp.x=sx;
temp.y=sy;
temp.z=sz;
temp.step=;
q.push(temp);
while(!q.empty())
{
temp=q.front();
q.pop();
if(temp.x==ex&&temp.y==ey&&temp.z==ez)
{
return temp.step;
}
for(int i=;i<;i++)
{
next=temp;
next.x = temp.x+to[i][];
next.y = temp.y+to[i][];
next.z = temp.z+to[i][];
if(check(next.x,next.y,next.z))
continue;
vis[next.x][next.y][next.z] = ;
next.step = temp.step+;
q.push(next);
}
}
return ; }
int main()
{
while(scanf("%d%d%d",&L,&R,&C)&&L!=&&R!=&&C!=)
{
for(int i=;i<L;i++)
for(int j=;j<R;j++)
{
scanf("%s",Map[i][j]);
for(int k=;k<C;k++)
{
if(Map[i][j][k]=='S')
{
sx=i;
sy=j;
sz=k;
}
else if(Map[i][j][k]=='E')
{
ex=i;
ey=j;
ez=k;
}
}
}
memset(vis,,sizeof(vis));
ans=;
ans=bfs();
if(ans)
printf("Escaped in %d minute(s).\n",ans);
else
printf("Trapped!\n"); }
}

Catch That Cow :http://poj.org/problem?id=3278

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
using namespace std;
#define INF 0x3f3f3f3f
typedef long long ll;
int N,K;
int ans;
int vis[];
struct node
{
int value;
int step;
};
int bfs()
{
node temp,next;
queue<node> q;
temp.value=N;
temp.step=;
vis[temp.value]=;
q.push(temp);
while(!q.empty())
{
temp=q.front();
// cout<<temp.value<<endl;
q.pop();
if(temp.value==K)
return temp.step;
next=temp;
for(int i=;i<;i++)
{
if(i==)
{
next.value=temp.value-;
}
if(i==)
{
next.value=temp.value+;
}
if(i==)
{
next.value=temp.value*;
}
if(next.value<||next.value>)
continue;
if(!vis[next.value])
{
// cout<<1<<endl;
vis[next.value]=;
next.step=temp.step+;
q.push(next);
}
}
}
return ; } int main()
{ while(scanf("%d%d",&N,&K))
{
memset(vis,,sizeof(vis));
ans=;
ans=bfs();
if(N>=K)
printf("%d\n",N-K);
else
printf("%d\n",ans);
} return ; }

ACM搜索问题盘点的更多相关文章

  1. ACM——搜索(一)

    南邮OJ——1108 搜索(一) 时间限制(普通/Java):3500MS/10500MS          运行内存限制:65536KByte总提交:1023            测试通过:367 ...

  2. 【ACM - 搜索模板】

    [广搜模板] #include <iostream> #include <stdio.h> #include <string.h> #include <que ...

  3. Mine Number(搜索,暴力) ACM省赛第三届 G

    Mine Number Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Every one once played the gam ...

  4. HDU 4900 NO ACM NO LIFE(概率+枚举+搜索)(2014 Multi-University Training Contest 4)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4900 Problem Description There is an old country and ...

  5. acm位运算应用 搜索

    acm位运算应用 搜索 搜索    此处不讲题目,只讲位运算是怎样在这些题中实现和应用的.由于搜索题往往是基于对状态的操作,位运算往往特别有效,优化之后的效果可以有目共睹.    例1.POJ 132 ...

  6. “玲珑杯”ACM比赛 Round #18--最后你还是AK了(搜索+思维)

    题目链接   DESCRIPTION INPUT OUTPUT SAMPLE INPUT 1 4 2 1 2 5 2 3 5 3 4 5 5 5 SAMPLE OUTPUT 35 HINT 对于样例, ...

  7. ACM International Collegiate Programming Contest, Tishreen Collegiate Programming Contest (2017)- K. Poor Ramzi -dp+记忆化搜索

    ACM International Collegiate Programming Contest, Tishreen Collegiate Programming Contest (2017)- K. ...

  8. 2013 ACM网络搜索与数据挖掘国际会议

    ACM网络搜索与数据挖掘国际会议" title="2013 ACM网络搜索与数据挖掘国际会议"> 编者按:ACM网络搜索与数据挖掘国际会议(6th ACM Conf ...

  9. ACM 暴力搜索题 题目整理

    UVa 129 Krypton Factor 注意输出格式,比较坑爹. 每次要进行处理去掉容易的串,统计困难串的个数. #include<iostream> #include<vec ...

随机推荐

  1. 洛谷P3381 - 【模板】最小费用最大流

    原题链接 题意简述 模板题啦~ 题解 每次都以费用作为边权求一下最短路,然后沿着最短路增广. Code //[模板]最小费用最大流 #include <cstdio> #include & ...

  2. java读取数据写入txt文件并将读取txt文件写入另外一个表

    package com.xsw.test; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.F ...

  3. webpack代码分离 ensure 看了还不懂,你打我(转)

    webpack异步加载的原理 webpack ensure相信大家都听过.有人称它为异步加载,也有人说做代码切割,那这 个家伙到底是用来干嘛的?其实说白了,它就是把js模块给独立导出一个.js文件的, ...

  4. angularjs1.6.4中使用ng-table出现data.slice is not a function的问题

    这个问题困扰了我2个小时. 项目中angularjs的版本从1.4.8升级到1.6.4,升级完成之后,发现ng-table不能用了.主要报错信息是ng-table中data.slice is not ...

  5. Android热修复(动态加载)方案汇总

    整理了以下动态加载的方案,便于在项目中使用时查阅: Dexposed github (https://github.com/alibaba/dexposed) AndFix github (https ...

  6. sdl的缩放问题

    SDL是一种既是开源的,也是跨平台的多媒体开发包,在各种平台上应用很广,经常和FFMPEG等解码器同时使用.对于在windows mobile等缺乏通用播放器的平台来说,是一种很好的选择.网上很多代码 ...

  7. php出现Can't use function return value in write context

    <?php if(session('uid')){ }else{ } ?> 在用empty判断值为空的时候,报了这个Can't use function return value in w ...

  8. freemarker自定义标签(一)

    freemarker自定义标签 1.自定义标签说明 宏变量存储模板片段可以被用作自定义指令macro 2.示例说明 <html> <head> <meta http-eq ...

  9. HTML5中的checkbox

    HTML5中的checkbox 1.选中checkbox (1)<input type="checkbox" checked/> (2)<input type=& ...

  10. canvas动画:自由落体运动

    经过前面的文章,我们已经能够在canvas画布上画出各种炫酷的图形和画面,但是这些画面都是禁止的,怎么样才能让他们动起来呢? 如何绘制基本图形可以参考:canvas基本图形绘制 如何对基本图形移动旋转 ...