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 ...
随机推荐
- Android 天气曲线
参考:http://blog.csdn.net/qy274770068/article/details/51560148
- Android利用Gson解析嵌套多层的Json
参考:http://www.cnblogs.com/jxgxy/p/3677256.html 比如我们要解析一个下面这种的Json: String json = {"a":&quo ...
- Swift - 语言指南,来自github学习
@SwiftLanguage 更新于 2016-6-6,更新内容详见 Issue 55.往期更新回顾详见<收录周报> 这份指南汇集了 Swift 语言主流学习资源,并以开发者的视角整理编排 ...
- ListView + PopupWindow实现滑动删除
原文:ListView滑动删除 ,仿腾讯QQ(鸿洋_) 文章实现的功能是:在ListView的Item上从右向左滑时,出现删除按钮,点击删除按钮把Item删除. 看过文章后,感觉没有必要把dispat ...
- ListView介绍
原文:http://blog.csdn.net/qingye_love/article/details/13772391?utm_source=tuicool&utm_medium=refer ...
- 数据结构和算法 – 7.散列和 Hashtable 类
7.1.散列函数 散列是一种常见的存储数据的技术,按照这种方式可以非常迅速地插入和取回数据.散列所采用的数据结构被称为是散列表.尽管散列表提供了快速地插入.删除.以及取回数据的操作,但是诸如查找最大值 ...
- 【转】JQuery插件ajaxFileUpload 异步上传文件(PHP版)
前几天想在手机端做个异步上传图片的功能,平时用的比较多的JQuery图片上传插件是Uploadify这个插件,效果很不错,但是由于手机不支持flash,所以不得不再找一个文件上传插件来用了.后来发现a ...
- .net学习之泛型、程序集和反射
一.泛型1.CLR编译时,编译器只为MyList<T>类型产生“泛型版”的IL代码——并不进行泛型的实例化,T在中间只充当占位符.例如:MyList 类型元数据中显示的<T> ...
- MVC4 使用概述
1.Bundle使用: http://www.cnblogs.com/inline/p/3897256.html 2.MVC总结: http://www.cnblogs.com/xlhblogs/ar ...
- POJ1351 Number of Locks(数学)
截至写博客为止,貌似这是网上第一个采用数学公式来处理的. 网上的题解都是DFS或是动态规划,但感觉可以推公式直接用数学的方法处理,想了好久,终于推出公式. 题意:一个长度为n的由数字1,2,3,4 组 ...