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 ...
随机推荐
- 获取真实Ip地址
/** * @author zhoulongqin * @see 获取客户端ip * @param * @return 客户端ip(String) webserve ip不一定获取的到 */ publ ...
- 我喜欢ASP.NET的MVC因为它牛逼的9大理由(转载)
我很早就关注ASP.NET的mvc的,因为最开始是学了Java的MVC,由于工作的原因一直在做.Net开发,最近的几个新项目我采用了MVC做了,我个一直都非常喜欢.Net的MVC.我们为什么使用MVC ...
- iOS小画板画线总结
一:基本画线: 使用贝赛尔曲线画: //创建路径 UIBezierPath* aPath = [UIBezierPath bezierPath]; //设置线宽 aPath.lineWidth = 5 ...
- 转:MVC 数据验证
一.基础特性 一.Required 必填选项,当提交的表单缺少该值就引发验证错误. 二.StringLength 指定允许的长度 指定最大长度: [StringLength()] //最大长度不超过2 ...
- Windows zabbix监控远程进程实现机制
最近负责zabbix监控部署方面的工作,需要完成本地服务端监控远程虚拟机的运行状态(CPU.打开的进程等),与大家分享下我的实现方法. (1) 首先,需要实现记录zabbix客户端的进程的批处理:za ...
- 级联两个bootstrap-table。一张表显示相关的数据,通过点击这张表的某一行,传过去对应的ID,刷新另外一张表。
二张表的代码(我用的插件,大家可以去网上直接下载http://issues.wenzhixin.net.cn/bootstrap-table/): <div class="contai ...
- LeetCode Plus One Linked List
原题链接在这里:https://leetcode.com/problems/plus-one-linked-list/ 题目: Given a non-negative number represen ...
- cmd导入导出
2:用cmd进入命令行输入:tnsping cmstar就是测试172.18.13.200是否连接成功3:导入与导出,如下: 数据导出: 1 将数据库TEST完全导出,用户名system 密码mana ...
- Union和Union All到底有什么区别
以前一直不知道Union和Union All到底有什么区别,今天来好好的研究一下,网上查到的结果是下面这个样子,可是还是不是很理解,下面将自己亲自验证: Union:对两个结果集进行并集操作,不包括重 ...
- .html(),.text()和.val()的差异总结:
.html(),.text()和.val()的差异总结: 1.html(),.text(),.val()三种方法都是用来读取选定元素的内容:只不过.html()是用来读取元素的html内容(包括htm ...