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 ...
随机推荐
- crontab执行时间和系统时间不一致
最近发现一个非常奇怪的问题,症状如下: crontab 定时任务 配置时间 是 10 5 * * * (每日凌晨5点10分执行) 运行脚本时间却是 18:10左右 Dec 24 05:10:01 ht ...
- python第一站
python 第一站,豆瓣-美国末日评论小爬虫 最近学习python,但是光是看书看视频学习,总是觉得掌握的不够扎实.所以就决定自己去写写爬虫,当带着目的性去学,也许更容易发现自己需要什么.这是酝酿多 ...
- 远程连接服务器for Linux
远程连接Linux云服务器-命令行模式 1.远程连接工具.目前Linux远程连接工具有很多种,您可以选择顺手的工具使用.下面使用的是名为Putty的Linux远程连接工具.该工具是免费的,且不需要安装 ...
- C学习笔记 知识集锦(一)
1.标识符 2.寄存器变量 3.全局变量 4.分配内存与初始化 5.变量定义与声明 6.作用域规则 跳转语句 7.&与&&,|和||的意义与区别 8.如何选择switch c ...
- Python之路----------shutil模块
高级的文件.文件夹.压缩包 处理模块 复制文件: import shutil f1 = open('test') f2 = open('test2','w') shutil.copyfileobj(f ...
- Xcode 运行cocos2dx弹出内部错误对话框(Internal Error)
cocos2dx未捕获的异常升高.选择"继续"继续运行在一个不一致的状态.选择"崩溃"停止应用和崩溃报告一个错误文件. 莫名其妙,代码没有报错,运行时却弹出(内 ...
- Ubuntu Kylin 14.04下配置JDK1.8
1.源码包准备: 首先到官网下载jdk,http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.h ...
- HDU 5063 Operation the Sequence(仔细审题)
http://acm.hdu.edu.cn/showproblem.php?pid=5063 题目大意: 题目意思还是比较简单.所以就不多少了.注意这句话,对解题有帮助. Type4: Q i que ...
- iframe载入页面过程显示动画效果
http://www.xfeixiang.com/Bug/Detail/A2FD7EFFA8CA72F1
- Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, ...