hdu 2209 bfs+状压
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+状压的更多相关文章
- hdu 5025 bfs+状压
http://acm.hdu.edu.cn/showproblem.php?pid=5025 N*N矩阵 M个钥匙 K起点,T终点,S点需多花费1点且只需要一次,1-9表示9把钥匙,只有当前有I号钥匙 ...
- hdu 1429 bfs+状压
题意:这次魔王汲取了上次的教训,把Ignatius关在一个n*m的地牢里,并在地牢的某些地方安装了带锁的门,钥匙藏在地牢另外的某些地方.刚开始 Ignatius被关在(sx,sy)的位置,离开地牢的门 ...
- HDU 4771 BFS + 状压
Stealing Harry Potter's Precious Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 ...
- C - 小明系列故事――捉迷藏 HDU - 4528 bfs +状压 旅游-- 最短路+状压
C - 小明系列故事――捉迷藏 HDU - 4528 这个题目看了一下题解,感觉没有很难,应该是可以自己敲出来的,感觉自己好蠢... 这个是一个bfs 用bfs就很好写了,首先可以预处理出大明和二明能 ...
- hdu 1044(bfs+状压)
非常经典的一类题型 没有多个出口.这里题目没有说清楚 Collect More Jewels Time Limit: 2000/1000 MS (Java/Others) Memory Limi ...
- hdu 5094 Maze (BFS+状压)
题意: n*m的迷宫.多多要从(1,1)到达(n,m).每移动一步消耗1秒.有P种钥匙. 有K个门或墙.给出K个信息:x1,y1,x2,y2,gi 含义是(x1,y1)与(x2,y2)之间有gi ...
- hdu 4771 Stealing Harry Potter's Precious (BFS+状压)
题意: n*m的迷宫,有一些格能走("."),有一些格不能走("#").起始点为"@". 有K个物体.(K<=4),每个物体都是放在& ...
- 孤岛营救问题 (BFS+状压)
https://loj.ac/problem/6121 BFS + 状压 写过就好想,注意细节debug #include <bits/stdc++.h> #define read rea ...
- HDU 5025:Saving Tang Monk(BFS + 状压)
http://acm.hdu.edu.cn/showproblem.php?pid=5025 Saving Tang Monk Problem Description <Journey to ...
随机推荐
- pie.htc 在IE下不起作用~~~
一直用的IE11 然后选择其中的兼容模式来测试IE 7~10的情况. 最近由于客户要求 圆角阴影兼容IE,只能选择PIE.HTC的方案. 但是反复测试发现不起作用. 官方文档的几种说明: 1. pie ...
- w3wp.exe已附加有调试器,但没有该调试器配置为调试此未经处理的异常,若要调试此异常,必须分离当前的调试器。
之前通过使用VS2010附加进程调试项目后,今天开机发现调试本机的项目报错如下图: 到网上到处查看无果,经过反复实验找到解决方法,我的项目是发布到IIS的 1.首先删除IIS上面的项目 2.在VS右击 ...
- 1045-access denied for user 'root'@
在用sqlyog图形界面远程登录阿里云mysql数据库的时候出现了如下的问题, 1045-access denied for user 'root'@ 刚开始以为阿里云esc的安全组并没有配置3306 ...
- Hiberante知识点梳理
Hibernate简介 Hibernat是一个ORM(关系映射)框架,对JDBC访问数据库的操作进行了简化,并且将数据库表中的字段和关系映射为对象,简化了对数据库的操作. 使用方法 读取并解析配置文件 ...
- ASP.NET没有魔法——ASP.NET MVC 过滤器(Filter)
上一篇文章介绍了使用Authorize特性实现了ASP.NET MVC中针对Controller或者Action的授权功能,实际上这个特性是MVC功能的一部分,被称为过滤器(Filter),它是一种面 ...
- [转载] 详述三种现代JVM语言--Groovy,Scala和Clojure
转载自http://www.tuicool.com/articles/jYzuAv和http://www.importnew.com/1537.html 在我与Martin Fowler曾经合作呈现的 ...
- SpringMVC---CookieValue
配置文件承接一二章 @CookieValue的作用 用来获取Cookie中的值 1.value:参数名称 2.required:是否必须 3.defaultValue:默认值 原网址:https:// ...
- PHP strftime()函数输出乱码问题
直接调用strftime() strftime(time_buf, 80, "%a, %e %b %G %T %z", p_stime); 输出为 Îå, 18 12ÔÂ 201 ...
- Audio Source组件及相关API
Audio Source:声音组件.需要与 Audio Listener 配合使用,Main Camera 会默认有 Audio Lisetener. Audio Clip:声音片段.指定需要播放的音 ...
- 《java.util.concurrent 包源码阅读》14 线程池系列之ScheduledThreadPoolExecutor 第一部分
ScheduledThreadPoolExecutor是ThreadPoolExecutor的子类,同时实现了ScheduledExecutorService接口. public class Sche ...