A - 棋盘问题

POJ - 1321

注意条件:不能每放一个棋子,就标记一行和一列,我们直接枚举每一行就可以了。

AC代码:

 #include<iostream>
#include<stdio.h>
#include<cstring>
using namespace std;
# define ll long long
const int maxn =;
char str[maxn][maxn];
int vis[maxn];
int n,m,num;
void dfs(int u,int cnt)
{
if(cnt==m)
{
num++;
return ;
}
if(u==n)
return ;
for(int i=; i<n; i++)
{
if(!vis[i]&&str[u][i]=='#')
{
vis[i]=;
dfs(u+,cnt+);
vis[i]=;
}
}
dfs(u+,cnt);
}
int main()
{
while(~scanf("%d %d",&n,&m))
{
if(n==-&&m==-)
break;
memset(vis,,sizeof(vis));
num=;
for(int i=; i<n; i++)
{
scanf("%s",str[i]);
}
dfs(,);
printf("%d\n",num);
}
return ;
}

B - Dungeon Master

POJ - 2251

注意条件:简单三维bfs。

AC代码:

 #include<iostream>
#include<stdio.h>
#include<cstring>
#include<queue>
using namespace std;
# define ll long long
const int maxn =;
char str[maxn][maxn][maxn];
int vis[maxn][maxn][maxn];
int f[][]= {{,-,,,,},
{,,-,,,},
{,,,,,-}
};
int n,m,k;
int stx,sty,stz;
int edx,edy,edz;
int ans;
bool judge(int x,int y,int z)
{
if(x>=&&x<=n&&y>=&&y<=m&&z>=&&z<=k)
return true;
return false;
}
struct node
{
int x,y,z,step;
node() {}
node(int xx,int yy,int zz,int tt)
{
x=xx,y=yy,z=zz,step=tt;
}
};
void bfs(int x,int y,int z)
{
queue<node>q;
q.push(node(x,y,z,));
vis[x][y][z]=;
while(!q.empty())
{
node top=q.front();
q.pop();
if(top.x==edx&&top.y==edy&&top.z==edz)
{
ans=top.step;
return ;
}
for(int i=; i<; i++)
{
int tx,ty,tz;
tx=top.x+f[][i];
ty=top.y+f[][i];
tz=top.z+f[][i];
if(judge(tx,ty,tz)&&vis[tx][ty][tz]==&&str[tx][ty][tz]!='#')
{
vis[tx][ty][tz]=;
q.push(node(tx,ty,tz,top.step+));
}
}
}
}
int main()
{
while(~scanf("%d %d %d",&n,&m,&k)&&(n+m+k))
{
memset(vis,,sizeof(vis));
ans=-;
for(int i=; i<=n; i++)
{
for(int j=; j<=m; j++)
{
scanf("%s",str[i][j]+);
for(int l=; l<=k; l++)
{
if(str[i][j][l]=='S')
{
stx=i;
sty=j;
stz=l;
}
if(str[i][j][l]=='E')
{
edx=i;
edy=j;
edz=l;
}
}
}
}
bfs(stx,sty,stz);
if(ans==-)
printf("Trapped!\n");
else
printf("Escaped in %d minute(s).\n",ans);
}
return ;
}

C - Catch That Cow

POJ - 3278

注意条件:bfs,注意限制条件。

AC代码:

 #include<iostream>
#include<stdio.h>
#include<cstring>
#include<queue>
using namespace std;
# define ll long long
const int maxn =2e5+;
int vis[maxn];
pair<int,int> top;
int bfs(int st,int ed){
queue<pair<int,int> >q;
vis[st]=;
q.push(make_pair(st,));
while(!q.empty()){
top=q.front();
q.pop();
if(top.first==ed){
return top.second;
}
if(top.first+<=ed&&vis[top.first+]==){
vis[top.first+]=;
q.push(make_pair(top.first+,top.second+));
}
if(top.first->=&&vis[top.first-]==){
vis[top.first-]=;
q.push(make_pair(top.first-,top.second+));
}
if(top.first*<=*ed&&vis[top.first*]==){
vis[top.first*]=;
q.push(make_pair(top.first*,top.second+));
}
}
}
int main(){
int n,m;
while(~scanf("%d %d",&n,&m)){
memset(vis,,sizeof(vis));
int ans=bfs(n,m);
printf("%d\n",ans);
}
return ;
}

D - Fliptile

POJ - 3279

注意条件:直接枚举第一行,然后通过下面的一行调整为他的上一行全为0.找出最小步骤,如果存在多个最小步骤相等。找出字典序最小的(对第一行二进制枚举就可以保证了)

AC代码:

 #include<iostream>
#include<stdio.h>
#include<cstring>
using namespace std;
# define ll long long
# define inf 0x3f3f3f3f
const int maxn = ;
int a[maxn][maxn];
int tmp[maxn][maxn];
int ans[maxn][maxn];
int com[maxn][maxn];
int n,m,ti;
void flip(int x,int y){
ti++;
tmp[x][y]^=;
tmp[x+][y]^=;
tmp[x-][y]^=;
tmp[x][y+]^=;
tmp[x][y-]^=;
}
bool judge(int t){
memcpy(tmp,a,sizeof(a));
memset(com,,sizeof(com));
for(int i=m;i>=;i--){
com[][m-i+]=((t&(<<(i-)))>?:);
}
for(int i=;i<=m;i++){
if(com[][i])flip(,i);
}
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
if(tmp[i-][j])flip(i,j),com[i][j]=;
}
}
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
if(tmp[i][j])return false;
}
}
return true;
}
int main(){
scanf("%d %d",&n,&m);
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
scanf("%d",&a[i][j]);
}
}
int maxstate=(<<m)-;
int maxx=inf;
for(int i=;i<=maxstate;i++){
ti=;
if(judge(i)){
if(maxx>ti){
maxx=ti;
memcpy(ans,com,sizeof(com));
}
}
}
if(maxx==inf){
printf("IMPOSSIBLE\n");
}
else {
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
if(j==)printf("%d",ans[i][j]);
else printf(" %d",ans[i][j]);
}
printf("\n");
}
}
return ;
}
//溜了,回家玩耍的

[kuangbin带你飞]专题一 简单搜索(回顾)的更多相关文章

  1. [kuangbin带你飞]专题一 简单搜索 回顾总结

    第二题:bfs,忘了将queue清空. 第三题:bfs,记得使用vis数组,防止重复入队

  2. [kuangbin带你飞]专题一 简单搜索 题解报告

    又重头开始刷kuangbin,有些题用了和以前不一样的思路解决.全部题解如下 点击每道题的标题即可跳转至VJ题目页面. A-棋盘问题 棋子不能摆在相同行和相同列,所以我们可以依此枚举每一行,然后标记每 ...

  3. [kuangbin带你飞]专题一 简单搜索 - E - Find The Multiple

    //Memory Time //2236K 32MS #include<iostream> using namespace std; ]; //保存每次mod n的余数 //由于198的余 ...

  4. [kuangbin带你飞]专题一 简单搜索 棋盘问题

    题来:链接https://vjudge.net/problem/OpenJ_Bailian-132 J - 棋盘问题 1.题目: 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别. ...

  5. [kuangbin带你飞]专题一 简单搜索

            ID Origin Title 454 / 1008 Problem A POJ 1321 棋盘问题   328 / 854 Problem B POJ 2251 Dungeon Ma ...

  6. 迷宫问题 POJ - 3984 [kuangbin带你飞]专题一 简单搜索

    定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, ...

  7. [kuangbin带你飞]专题一 简单搜索 Find a way HDU - 2612

    Pass a year learning in Hangzhou, yifenfei arrival hometown Ningbo at finally. Leave Ningbo one year ...

  8. Catch That Cow POJ - 3278 [kuangbin带你飞]专题一 简单搜索

    Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. ...

  9. Dungeon Master POJ - 2251 [kuangbin带你飞]专题一 简单搜索

    You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of un ...

随机推荐

  1. 第三节,使用OpenCV 3处理图像(模糊滤波、边缘检测)

    一 不同色彩空间的转换 OpenCV中有数百种关于在不同色彩空间之间转换的方法.当前,在计算机中有三种常用的色彩空间:灰度,BGR以及HSV(Hue,Saturation,Value). 灰度色彩空间 ...

  2. jmeter的介绍和使用二

    三. 1.http的请求默认值 当一个项目有多个模块,他们的host都是一致的,为了不重复的写host或者当某一天host变了,只需要修改一个地方就好.比如下面的两个请求,可以把host分离出来,所以 ...

  3. Codeforces Gym 191033 E. Explosion Exploit (记忆化搜索+状压)

    E. Explosion Exploit time limit per test 2.0 s memory limit per test 256 MB input standard input out ...

  4. C#Windows服务程序安装常见问题解决方法

    C#Windows服务程序安装是如何的呢?让我们开始吧: C#Windows服务程序安装1. 在服务程序的是设计窗体中,点击右键“添加安装程序”,添加服务安装程序.否则,安装时会出现如下 错误: 正在 ...

  5. spring的设计模式

    spring中用到哪些设计模式   1.工厂模式,这个很明显,在各种BeanFactory以及ApplicationContext创建中都用到了: 2.模版模式,这个也很明显,在各种BeanFacto ...

  6. 基于RBAC模型的权限系统设计(Github开源项目)

    RBAC(基于角色的访问控制):英文名称Rose base Access Controller.本博客介绍这种模型的权限系统设计.取消了用户和权限的直接关联,改为通过用户关联角色.角色关联权限的方法来 ...

  7. servlet模拟SpringMVC

    1. web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi=&q ...

  8. 20165232 2017-2018-2《Java程序设计》课程总结

    20165232 2017-2018-2<Java程序设计>课程总结 每周作业链接汇总: 我期望的师生关系 学习基础和c语言基础调查 预备作业3 Linux安装及学习 第一周学习总结 第二 ...

  9. spark常见异常汇总

    spark常见异常汇总 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 温馨提示:   如果开发运行spark出现问题啦,可能需要运维这边做一些调优,也可能是开发那边需要修改代码.到 ...

  10. Java插件之Jrebel

    Jrebel是干嘛的?当你在Java Web的项目中修改一些代码的时候(成员代码),想要生效必须重启服务器.但是每次修改代码都得重启服务器?重启着时间很长的,太麻烦了. Jrebel隆重出场,它可以使 ...