BZOJ3979 : [WF2012]infiltration
答案是$O(\log n)$级别的,故答案不超过6。
当答案是12345时,暴力枚举+压位检验即可,否则直接输出6。
时间复杂度$O(n^5)$。
#include<cstdio>
#define N 80
#define rep(i,n) for(int i=0;i<n;i++)
typedef unsigned int U;
int n,T;char s[N];
struct P{
U x,y,z;
P(){x=y=z=0;}
P(U _x,U _y,U _z){x=_x,y=_y,z=_z;}
inline P operator|(const P&b){return P(x|b.x,y|b.y,z|b.z);}
inline void set(int p){
if(p<32){x|=1U<<p;return;}
p-=32;
if(p<32){y|=1U<<p;return;}
z|=1U<<(p-32);
}
inline int cnt(){return __builtin_popcount(x)+__builtin_popcount(y)+__builtin_popcount(z);}
}g[N],S;
inline bool one(){
rep(i,n)if(g[i].cnt()==n)return 1;
return 0;
}
inline bool two(){
rep(i,n)rep(j,i)if((g[i]|g[j]).cnt()==n)return 1;
return 0;
}
inline bool three(){
rep(i,n)rep(j,i)rep(k,j)if((g[i]|g[j]|g[k]).cnt()==n)return 1;
return 0;
}
inline bool four(){
rep(i,n)rep(j,i)rep(k,j)rep(l,k)if((g[i]|g[j]|g[k]|g[l]).cnt()==n)return 1;
return 0;
}
inline bool five(){
rep(i,n)rep(j,i)rep(k,j)rep(l,k)rep(m,l)if((g[i]|g[j]|g[k]|g[l]|g[m]).cnt()==n)return 1;
return 0;
}
int main(){
while(~scanf("%d",&n)){
printf("Case %d: ",++T);
rep(i,n){
scanf("%s",s);
g[i]=P();
g[i].set(i);
rep(j,n)if(s[j]=='1')g[i].set(j);
}
if(one()){puts("1");continue;}
if(two()){puts("2");continue;}
if(three()){puts("3");continue;}
if(four()){puts("4");continue;}
if(five()){puts("5");continue;}
puts("6");
}
return 0;
}
BZOJ3979 : [WF2012]infiltration的更多相关文章
- [WF2012]infiltration
[WF2012]infiltration 完全图 最多选择logn个点(下取整)(每选择一个点覆盖至少一半的规模) 暴力O(75^5)(不严格)枚举+bitset (随机化也可过) #include& ...
- bzoj 3979: [WF2012]infiltration【瞎搞+随机化】
参考:https://www.cnblogs.com/ccz181078/p/5622200.html 非常服气.jpg 就是random_shuffle几次然后顺着找,ans取min... #inc ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- bzoj 3978: [WF2012]Fibonacci Words
Description 斐波那契01字符串的定义如下 F(n) = { 0 if n = 0 1 if n = 1 F(n-1)+F(n-2) if n >= 2 } 这里+的定义是字符串的 ...
- [WorldFinal 2012E]Infiltration(dfs+图论)
Description 题意:给定一个点数为n的竞赛图,求图的最小支配集 n<=75 Solution 如果将竞赛图的一个点删去,这个图还是竞赛图 而竞赛图每个点相连的边数为(n-1),那么删去 ...
- Constructing continuous functions
This post summarises different ways of constructing continuous functions, which are introduced in Se ...
- 做数据挖掘,就算发 20 几分的 CNS 子刊,也是垃圾!?--转载
关于数据挖掘发表文章,我们知道很多人是看不上.瞧不起.嗤之以鼻的.大抵是因为这些人平时只发 CNS 主刊,所以才认为通过数据挖掘这种用「别人的数据」或者叫「干实验」来发文章是“「垃圾」,没有什么价值. ...
- Can peel peel solve pesticide problem
Can peel peel solve pesticide problem? Middle peasants medicinal modern agriculture more and more, t ...
- Cryptographic method and system
The present invention relates to the field of security of electronic data and/or communications. In ...
随机推荐
- DB2 for Z/os Statement prepare
The PREPARE statement creates an executable SQL statement from a string form of the statement. The c ...
- myaql常用函数
一.数学函数 abs(x) 返回x的绝对值 bin(x) 返回x的二进制(oct返回八进制,hex返回十六进制) ceiling(x) 返回大于x的最小整数值 exp(x) 返回值e( ...
- webservice 简单入门 (NLY)
1,创建webservice服务器端 搭建网站,创建webservice webservice.cs中的代码 namespace WebApplication1 { /// <summary&g ...
- mysqlbinlog 查看日志时发生报错
[root@cs Downloads]# mysqlbinlog mysql-bin. ERROR: Error , event_type: ERROR: Could not read entry a ...
- Linq to json
Json.Net系列教程 4.Linq To JSON 一.Linq to JSON是用来干什么的? Linq to JSON是用来操作JSON对象的.可以用于快速查询,修改和创建JSON对象.当JS ...
- linux中创建gpio节点
转自:http://blog.chinaunix.net/uid-29165999-id-4296162.html #define GPIO_MAJOR 230 // major device NO. ...
- Pyqt QListWidget之缩略图列表
QListWidget 可以设置模型setViewMode 当setViewMode值为QListView.IconMode 表示Icon模式 以下代码来自Pyqt Example #!/usr/b ...
- 【PHP小项目使用MVC架构】
小项目名称是雇员管理系统. mvc是一种项目的开发模式,中文名称为模式视图控制器,是强制程序员将数据的输入.处理.输出分开的一种开发模式. 在这个小项目中,控制器使用service作为后缀名. 项目u ...
- Centos6.5里安装Erlang 并安装riak
一.Erlang安装: 1 首先进入www.erlang.org 下载页面,下载otp_src_17.5.tar.gz. IT网,http://www.it.net.cn 2 解压缩:tar -xzv ...
- Golang gopath
golang 的gopath 至关重要,会影响到我们import package. golang 支持以相对路径的方式import,但是这种方式是不推荐的. 推荐的做法是在gopath中添加我们的项目 ...