http://acm.hdu.edu.cn/showproblem.php?pid=2209

不知为啥有种直觉。会出状压+搜索的题,刷几道先

简单的BFS。状压表示牌的状态,

//#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <map>
#include <set>
#include <queue>
using namespace std; #define ls(rt) rt*2
#define rs(rt) rt*2+1
#define ll long long
#define ull unsigned long long
#define rep(i,s,e) for(int i=s;i<e;i++)
#define repe(i,s,e) for(int i=s;i<=e;i++)
#define CL(a,b) memset(a,b,sizeof(a))
#define IN(s) freopen(s,"r",stdin)
#define OUT(s) freopen(s,"w",stdout)
const ll ll_INF = ((ull)(-1))>>1;
const double EPS = 1e-8;
const double pi = acos(-1.0);
const int INF = 100000000; int len,s;
int vis[1<<21];
char in[50];
int legal[25];
struct Node{
int s;
int cnt;
Node(int ss,int cc):s(ss),cnt(cc){}
}; void change()
{
s=0;
len=strlen(in);
for(int i=0;i<len;i++)
{
s<<=1;
if(in[i] == '1')s+=1;
}
} int bfs()
{
queue<Node>q;
q.push(Node(s,0));
CL(vis,0);
vis[s]=1;
while(!q.empty())
{
Node tp=q.front();q.pop();///
if(tp.s==0)return tp.cnt;
int s,cnt=tp.cnt+1;
for(int i=0;i<len;i++)
{
if(i==0)s=tp.s^3;
else
{
if(i==len-1)s=tp.s^(3<<(len-2));//
else s=(tp.s^(7<<(i-1)));
}
if(!vis[s])
{
vis[s]=1;
q.push(Node(s,cnt));
} } }
return -1;
} int main()
{
//IN("hdu2209.txt");
while(~scanf("%s",in))
{
change();
int ans=bfs();
if(ans==-1)puts("NO");
else printf("%d\n",bfs());
}
return 0;
}

hdu 2209 bfs+状压的更多相关文章

  1. hdu 5025 bfs+状压

    http://acm.hdu.edu.cn/showproblem.php?pid=5025 N*N矩阵 M个钥匙 K起点,T终点,S点需多花费1点且只需要一次,1-9表示9把钥匙,只有当前有I号钥匙 ...

  2. hdu 1429 bfs+状压

    题意:这次魔王汲取了上次的教训,把Ignatius关在一个n*m的地牢里,并在地牢的某些地方安装了带锁的门,钥匙藏在地牢另外的某些地方.刚开始 Ignatius被关在(sx,sy)的位置,离开地牢的门 ...

  3. HDU 4771 BFS + 状压

    Stealing Harry Potter's Precious Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 ...

  4. C - 小明系列故事――捉迷藏 HDU - 4528 bfs +状压 旅游-- 最短路+状压

    C - 小明系列故事――捉迷藏 HDU - 4528 这个题目看了一下题解,感觉没有很难,应该是可以自己敲出来的,感觉自己好蠢... 这个是一个bfs 用bfs就很好写了,首先可以预处理出大明和二明能 ...

  5. hdu 1044(bfs+状压)

    非常经典的一类题型 没有多个出口.这里题目没有说清楚 Collect More Jewels Time Limit: 2000/1000 MS (Java/Others)    Memory Limi ...

  6. hdu 5094 Maze (BFS+状压)

    题意: n*m的迷宫.多多要从(1,1)到达(n,m).每移动一步消耗1秒.有P种钥匙. 有K个门或墙.给出K个信息:x1,y1,x2,y2,gi    含义是(x1,y1)与(x2,y2)之间有gi ...

  7. hdu 4771 Stealing Harry Potter's Precious (BFS+状压)

    题意: n*m的迷宫,有一些格能走("."),有一些格不能走("#").起始点为"@". 有K个物体.(K<=4),每个物体都是放在& ...

  8. 孤岛营救问题 (BFS+状压)

    https://loj.ac/problem/6121 BFS + 状压 写过就好想,注意细节debug #include <bits/stdc++.h> #define read rea ...

  9. HDU 5025:Saving Tang Monk(BFS + 状压)

    http://acm.hdu.edu.cn/showproblem.php?pid=5025 Saving Tang Monk Problem Description   <Journey to ...

随机推荐

  1. linux分析日志的一些常用方法

    head -n 2016_05_23_access_log |grep "/859" 显示前10000行中包含 /859 的记录 增加 |wc -l  则改为输出记录数 cat 2 ...

  2. 运维必须掌握的150个Linux命令

    线上查询及帮助命令(1个)man 目录操作命令(6个)ls tree pwd mkdir rmdir cd 文件操作命令(7个)touch cp mv rm ln find rename 文件查看及处 ...

  3. 对比MFC和Winform及WPF

    MFC 生成本机代码,自然是很快.可是,消息循环,减缓了界面显示速度.winform 封装了 win32 的api,多次进行P/invoke 操作 (大部分使用p/invoke操作封装),速度慢 .w ...

  4. 100000个嵌入式学习者遇到的PING不通问题,我们使用这一个视频就解决了,牛!

    在10多年的售后答疑历程中,我们每天都会遇到开发板.windows,ubuntu三者之间的PING通问题,常常中断手头中的工作去解决这类问题,甚至跟客户远程协助,颇耗时间与精力,在热心网友.答疑助手们 ...

  5. linux操作系统基础篇(二)

    Linux用户.群组.权限 1.用户也是由一个个文件组成的下列文件都是存放用户信息的文件 useradd user1 /etc/passwd: 存放用户信息  /etc/shadow/ :存放用户密码 ...

  6. Python之hashlib模块

    hashlib 在做一个授权管理系统,需要生产动态生成密码,故使用hashlib >>> import time >>> import hashlib >&g ...

  7. 如何开发一个chrome扩展

    chrome是一个不错的浏览器,web开发者工作中一般都会使用chrome做为默认浏览器,它有很多扩展,给浏览器补充了各种功能,增强了用户体验.chrome具体能干什么?怎么做出来的呢? chrome ...

  8. 在windows下vs使用pthread

    首先从http://sourceware.org/pthreads-win32/下载pthread 的windows安装包,我下的是pthread-w32-2-9-1-release.zip,其他版本 ...

  9. listviewMyAdapter

    import android.content.Context;import android.graphics.Bitmap;import android.graphics.BitmapFactory; ...

  10. C#爬虫系列(二)——食品安全国家标准数据检索平台

    上篇对“国家标准全文公开系统”的国标进行抓取,本篇对食品领域的标准公开系统“食品安全国家标准数据检索平台”进行抓取. 平台地址:http://bz.cfsa.net.cn/db 一.标准列表 第一步还 ...