参考:https://www.cnblogs.com/ccz181078/p/5622200.html

非常服气.jpg

就是random_shuffle几次然后顺着找,ans取min...

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
int n,ans,cas,a[100],tot,c[100],s[100],top;
char ch[100][100];
int main()
{
srand(1844677);
while(~scanf("%d",&n))
{
for(int i=0;i<n;i++)
{
scanf("%s",ch[i]),ch[i][i]='1';
for(int j=0;j<n;j++)
ch[i][j]-='0';
}
ans=n;
int ca=180;
while(ca--&&ans>1)
{
top=0;
for(tot=0;tot<n;tot++)
a[tot]=tot,c[tot]=0;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
if(ch[i][j])
++c[j];
for(int t=0;t<5;t++)
{
random_shuffle(a,a+tot);
for(int i=0;i<tot;i++)
{
int x=a[i];
bool ed=1;
for(int j=0;j<n;j++)
if(ch[x][j]>=c[j])
{
ed=0;
break;
}
if(ed)
{
for(int j=0;j<n;j++)
if(ch[x][j])
c[j]--;
s[top++]=x;
a[i--]=a[--tot];
}
}
if(tot<ans)
ans=tot;
if(!top)
continue;
int w=rand()%top,x=a[tot++]=s[w];
s[w]=s[top--];
for(int i=0;i<n;i++)
if(ch[x][i])
c[i]++;
}
}
printf("Case %d: %d\n",++cas,ans);
}
return 0;
}
/*
2
00
10
3
010
001
100
5
01000
00011
11001
10100
10010
4
0100
0000
1100
1110
4
0011
1011
0001
0000
4
0101
0010
1001
0100
6
001110
100001
010010
011010
010001
101100
4
0000
1001
1100
1010
7
0100011
0000100
1100001
1110111
1010011
0110000
0100010
7
0010001
1011111
0001111
1000110
1000000
1000100
0001110
*/

bzoj 3979: [WF2012]infiltration【瞎搞+随机化】的更多相关文章

  1. BZOJ 4236: JOIOJI map瞎搞

    分别记录J,O,I,的个数 cnt[char][i] 表示处理到第i位,char的个数 显然当且仅当 cnt[J][i] - cnt[O][i] == cnt[J][j-1] - cnt[O][j-1 ...

  2. bzoj 4080: [Wf2014]Sensor Network【瞎搞+随机化】

    参考:https://blog.csdn.net/YihAN_Z/article/details/73380387 一点都不想写正解.jpg random_shuffle一下然后贪心的加点,和ans取 ...

  3. bzoj 2456: mode【瞎搞】

    这题加个#include都会MLE-- 神思路,每个数抵消宇哥和它不同的数,最后剩下的就是众数 #include<cstdio> int n,la,x,tot; int main() { ...

  4. [WF2012]infiltration

    [WF2012]infiltration 完全图 最多选择logn个点(下取整)(每选择一个点覆盖至少一半的规模) 暴力O(75^5)(不严格)枚举+bitset (随机化也可过) #include& ...

  5. URAL 1203. Scientific Conference(瞎搞)

    题目链接 本来觉得这不是经典的贪心吗..果断水一次,wa了,看了看discuss,发现貌似不好水,土土的DP了一下,复杂度很高了,又T了...然后想想单调队列,二分什么的...不好往上加,直接搞了标记 ...

  6. Codeforces Gym 100610 Problem H. Horrible Truth 瞎搞

    Problem H. Horrible Truth Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1006 ...

  7. B. Salty Fish Go! -期望题(瞎搞题)

    链接:https://www.nowcoder.com/acm/contest/104/B来源:牛客网 题意:A few days ago, WRD was playing a small game ...

  8. HDU5532 Almost Sorted Array(最长上升子序列 or 瞎搞个做差的数组)

    题目链接:点我 题意:给定一个序列,询问是否能删除一个数让它成为非递减或者非递增的序列. 比如说 删除后的序列是1 3 3 5 或者5 3 3 1 或者1 3 5 或者5 3 1 都可以.只要满足删掉 ...

  9. TOJ3097: 单词后缀 (字典树 or map瞎搞)

    传送门 (<---可以点击的~) 时间限制(普通/Java):1000MS/3000MS     内存限制:65536KByte 描述 有些英语单词后缀都是一样的,现在我们需要从给定的一堆单词里 ...

随机推荐

  1. WKWebView的了解

    1. http://blog.csdn.net/chenyong05314/article/details/53735215 2. http://www.jianshu.com/p/6ba250744 ...

  2. 一个Tomcat最多支持多少用户的并发?

    ,也就是说同时支持 另外,在 Java 中每开启一个线程需要耗用 1MB 的 JVM 内存空间用于作为线程栈之用.Tomcat的最大并发数是可以配置的,实际运用中,最大并发数与硬件性能和CPU数量都有 ...

  3. Vue基础学习

    使用vue-cli构建初始化vue项目 vue init webpack myfirst 项目截图:(开发工具:webStorm) 主要练习了vue的基本指令:v-bind.v-if.v-show.v ...

  4. 【Perl】perl正则表达式中的元字符、转义字符、量词及匹配方式

    Linux平台上被广泛使用的正则表达式库PCRE - Perl-compatible regular expressions,从其名字即可知道,PCRE提供的是一套与Perl中相兼容的正则表达式. 元 ...

  5. Eclipse注释模板配置

    不过感觉作用不大,因为@date这些不是标准的Java注释.

  6. Maven创建项目时出现Generating project in Interactive mode就一直卡住的解决方案

    使用maven命令在创建项目的时候出现 Generating project in Interactive mode 然后就一直卡住 网上搜做了很多解决方案 有说各种方案的,最后找到了一种.实验成功 ...

  7. arcgis安装路径的获得

    //Get the ArcGIS install location string sInstall = ESRI.ArcGIS.RuntimeManager.ActiveRuntime.Path; / ...

  8. Office PDF如何旋转页面之后保存

    直接视图-旋转视图-逆时针,是不行的,旋转之后无法保存,另存为之后也再打开也没有效果.   要点击视图-工具-页面   然后在右边的菜单中点击旋转,然后执行旋转,然后就可以保存了.        

  9. yii2利用自带UploadedFile上传图片

    创建一个 models/UploadForm.php: <?php namespace app\models; use yii\base\Model; use yii\web\UploadedF ...

  10. curl_setopt GET的方法

    $ch ") ; curl_setopt($ch, CURLOPT_RETURNTRANSFER, true) ; curl_setopt($ch, CURLOPT_BINARYTRANSF ...