参考: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. 利用开源工具实现轻量级上网行为审计(来源ispublic.com)

    https://blog.csdn.net/cnbird2008/article/details/5875781

  2. Codeforces Manthan, Codefest 18 (rated, Div. 1 + Div. 2) D,E

    D. Valid BFS? time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  3. 洛谷—— P2802 回家

    P2802 回家 题目描述 小H在一个划分成了n*m个方格的长方形封锁线上. 每次他能向上下左右四个方向移动一格(当然小H不可以静止不动), 但不能离开封锁线,否则就被打死了. 刚开始时他有满血6点, ...

  4. FlashFXP绿色版

    http://www.xdowns.com/soft/1/98/2006/Soft_30927.html

  5. Excel小tips - 如何实现多列成绩统一排名

    本文参考:http://mp.weixin.qq.com/s/XR49hyG9Cods7rOcsM-tRg 如果有以下数据文件,需要进行成绩排名. 第一步:先在成绩列后边添加一列,用来显示名次.如下: ...

  6. 信号量学习 & 共享内存同步

    刚刚这篇文章学习了共享内存:http://www.cnblogs.com/charlesblc/p/6142139.html 里面也提到了共享内存,自己不进行同步,需要其他手段比如信号量来进行.那么现 ...

  7. Django学习系列之request对象

    先来一个简单的实例 urls.py from django.conf.urls import url from django.contrib import admin from cmdb import ...

  8. [Rust] Setup Rust for WebAssembly

    In order to setup a project we need to install the nightly build of Rust and add the WebAssembly tar ...

  9. lightoj 1138 - Trailing Zeroes (III)【二分】

    题目链接:http://lightoj.com/volume_showproblem.php? problem=1138 题意:问 N. 末尾 0 的个数为 Q 个的数是什么? 解法:二分枚举N,由于 ...

  10. com.squareup.timessquare.CalendarPickerView

    com.squareup.timessquare.CalendarPickerView https://github.com/square/android-times-square