深度搜索:棋盘问题,详见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. SpringBoot application.yml logback.xml,多环境配置,支持 java -jar --spring.profiles.active

    趁今天有时间整理了一下 启动命令为 //开发环境 java -jar app.jar --spring.profiles.active=dev--server.port=8060 //测试环境 jav ...

  2. iOS开发之emoji处理

    看似emoji处理应该和我们iOS开发有着很大的关系,实则不然,对于emoji的处理只要在服务器端做就可以了,我所说的处理是我们将表情提交到服务器,那么在服务器端需要做些什么处理呢? 服务器如果直接存 ...

  3. linux nginx常见问题及优化,压力测试,tomcat服务器优化

    nginx常见问题 nginx优化全局配置优化[root@web2 nginx]# vim conf/nginx.confuser nobody;worker_processes 1;(与cpu核心数 ...

  4. Linux CentOS安装配置MySQL数据库

    没什么好说的,直接正面刚吧. 安装mysql数据库 a)下载mysql源安装包:wget http://dev.mysql.com/get/mysql57-community-release-el7- ...

  5. Pokémon Go呼应设计:让全世界玩家疯狂沉迷

    引言:什么样的呼应设计会让移动游戏玩家沉迷?那必须为玩家构建一个属于玩家本人或者被玩家认可的虚拟环境,或者说是被玩家认可的虚拟世界.在移动游戏时代,想要做到这一点并不容易.但Pokémon Go却做到 ...

  6. Jenkins Android 自动打包配置

    一.Jenkins自动打包配置 目标:1. 自动打包:2. 自动上传:3. 友好下载 1. Jenkins简介 Jenkins是基于Java开发的一种持续集成工具,用于监控持续重复的工作. 减少重复劳 ...

  7. 图像处理------Mean Shift滤波(边缘保留的低通滤波)

    一:Mean Shift算法介绍 Mean Shift是一种聚类算法,在数据挖掘,图像提取,视频对象跟踪中都有应用.本文 重要演示Mean Shift算法来实现图像的低通边缘保留滤波效果.其处理以后的 ...

  8. java.sql.SQLException: Access denied for user 'sa'@'localhost' (using password: YES)

    1.错误描述 ERROR:2015-05-01 23:43:04[localhost-startStop-1] - HHH000319: Could not get database metadata ...

  9. 使用VLC和live555MediaServer搭建RTSP服务器

    一.使用VLC搭建 服务端 1.打开"媒体--流"选项,如图所示:  2.点击"添加"按钮选择流媒体文件,然后点击"串流"按钮  3.点击& ...

  10. C# 带偏移量自定义分页方法

    /// <summary> /// 带偏移量自定义分页方法 /// </summary> /// <param name="PageSize"> ...