bzoj1080
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1080
神暴力,待搞懂.
代码
#include <cstdio>
#include <cmath>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#define ll long long
using namespace std;
typedef vector<int> ve;
map <ve,int> hash;
queue<ve>q;
string s[35];
int n;
void work()
{
ve u,v,t;
for (int i=1;i<=n;i++)
if (s[i]=="")
{
printf("0");
exit(0);
}
else u.push_back(i<<6);
hash[u]=0;
for(q.push(u);!q.empty();)
{
u=q.front();
q.pop();
int x=hash[u],cnt;
for (int ch='0';ch<='1';ch++)
{
cnt=0;
v.clear();
for (int i=0;i<u.size();i++)
{
int which=u[i]>>6,where=u[i]&63;
if (s[which][where]^ch) continue;
if(++where==s[which].size()) {
++cnt;
for (int j=1;j<=n;j++)v.push_back(j << 6);
}else v.push_back(which<<6|where);
}
if(cnt>=3)
{
printf("%d",x+1);
exit(0);
}
sort(v.begin(),v.end());
t.clear();
for (int i=0;i<v.size();i++)
{
if(i<3||v[i]^v[i-3]) t.push_back(v[i]);
}
int &th=hash[t];
if (t.size()&&!th) th=x+1,q.push(t);
}
}
printf("-1");
}
int main()
{
scanf("%d",&n);
for (int i=1;i<=n;i++) cin>>s[i];
work();
return 0;
}
bzoj1080的更多相关文章
- BZOJ1080 暴力+位移运算符的用法
1080: [SCOI2008]劣质编码 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 337 Solved: 148[Submit][Status ...
- BZOJ第1页养成计划
嗯,用这篇博客当一个目录,方便自己和学弟(妹?)们查阅.不定期更新. BZOJ1000 BZOJ1001 BZOJ1002 BZOJ1003 BZOJ1004 BZOJ1005 ...
随机推荐
- [dpdk] 熟悉SDK与初步使用 (二)(skeleton源码分析)
接续前节:[dpdk] 熟悉SDK与初步使用 (一)(qemu搭建实验环境) 程序逻辑: 运行参数: 关键API: 入口函数: int rte_eal_init(int argc, char **ar ...
- 点击input时,里面默认字体消失显示
点击input时,点击input里面默认字体消失显示: <input type="" name="" id="" value=&quo ...
- 使用 apache2 + `mod_proxy_uwsgi` + uwsgi + upstart 部署
使用 apache2 + mod_proxy_uwsgi + uwsgi + upstart 部署 网上运行 python wsgi 的应用时,大部分的资料都是使用 nginx .uwsgi ,很少资 ...
- Power-BI 预警触发的设定
在现实的业务场景,当某一区域的销售额低于一定的值时,那么就要引起重视了.我们希望当发生这种情况时,通过邮件或微信通知用户进行关注.Power-BI 预警触发功能就可以实现这个功能.一.设定公共参数1. ...
- LuaSrcDiet工具介绍(lua源码处理软件)
Diet Food Diet (nutrition), the sum of the food consumed by an organism or group Dieting, the delibe ...
- IE or Chrome can not use localhost, firefox can works.
因为服务器开启'localhost:9999",使用IE无法登陆,firefox下正常. 遂查看cookie,果然没有写入. stackoverflow.com: "ie enab ...
- ubuntu启动tomcat出错解决方案
从终端进入tomcat的bin目录,然后执行startup.sh,出现以下异常: Cannot find ./catalina.sh The file is absent or does not ha ...
- 记一次MVC4站点在IIS上部署的诡异问题
最近朋友的公司遇到一个站点部署问题, 朋友从事服务器维护多年,说也是花了十多天仍为解决. 经多次尝试未果,仍报错如下: 我询问了相关情况,确认了该网站是VS2013开发的,版本为,NET Framew ...
- python 数据库
什么是数据库? 数据库(Database)是按照数据结构来组织.存储和管理数据的仓库,每个数据库都有一个或多个不同的API用于创建,访问,管理,搜索和复制所保存的数据.我们也可以将数据存储在文件中,但 ...
- (转)学习使用Jmeter做压力测试(一)--压力测试基本概念
一.性能测试的概念 性能测试是通过自动化的测试工具模拟多种正常峰值及异常负载条件来对系统的各项性能指标进行测试.负载测试和压力测试都属于性能测试,两者可以结合进行. 通过负载测试,确定在各种工作负载下 ...