参考: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. hdu - 5007 Post Robot (水题)

    http://acm.hdu.edu.cn/showproblem.php?pid=5007 #include<iostream> #include<stdio.h> #inc ...

  2. 洛谷——P1951 收费站_NOI导刊2009提高(2)

    https://www.luogu.org/problem/show?pid=1951 题目描述 在某个遥远的国家里,有n个城市.编号为1,2,3,…,n. 这个国家的政府修建了m条双向的公路.每条公 ...

  3. Junit中Assert.assertEquals()和Assert.assertSame方法有什么异同

    1)提供的接口数量不完全相同.assertEquals支持boolean,long,int等等java primitiveType变量.assertSame只支持Object. 2)比较的逻辑不同,结 ...

  4. Spring Data Redis与Jedis的选择(转)

    说明:内容可能有点旧,需要在业务上做权衡. Redis的客户端有两种实现方式,一是可以直接调用Jedis来实现,二是可以使用Spring Data Redis,通过Spring的封装来调用.应该使用哪 ...

  5. oracle rac 安装错误整理。

    今天是2014.05.26,离别N久的博客今天继续使用. 近期一直忙着离职.入职另外加上家的网一直没有交费,弄的自己開始不那么安稳.学习就是须要一种心情平静.内心稳妥的去进行. 因换笔记本,特须要又一 ...

  6. java native interface JNI 调用Java方法

    在上一篇文章中介绍了JNI.以及java调用JNI.这篇讲一下 JNI调用java方法. 通过使用合适的JNI函数,你能够创建Java对象,get.set 静态(static)和 实例(instanc ...

  7. Mark 创建路径(c#)-动态分段

    http://bbs.esrichina-bj.cn/ESRI/viewthread.php?action=printable&tid=128564 public void CreateRou ...

  8. 实例 mount新硬盘方法

    0.建立挂载文件夹: mkdir /mnt/sdb1 1 .查看新硬盘: fdisk -l 2. 硬盘分区: fdisk /dev/sdb1 根据提示,依次输入 n, p, 1, 以及两次回车,然后是 ...

  9. 类的相互依赖导致StackOverflowError

    public class SchoolServiceImpl { private static SchoolServiceImpl instance = new SchoolServiceImpl() ...

  10. 战五渣系列之八(绝杀AOP)

    开发不用aop.程序猿的人生该会浪费多少时间.我想是时候让程序猿打败alpha狗了.程序猿解救世界. 1.概念 面向切面编程.这意味着,一切不在流水线上的东西.包含权限.日志.缓存.校验.资源.事物. ...