链接

题解

显然,最多抽2个集合

如果一直抽一个,前提是该集合有重复的,答案是不同元素的个数+1

如果抽两个,那么最坏情况下,在一个集合中抽到某一个数的次数是这个集合不同元素的个数(因为抽不到重复的)

枚举其中一个集合 \(S\) ,对于每一种元素,令 \(f[i]\) 表示第 \(i\) 个元素在其他集合中最少要多少次抽到,将 \(f\) 数组从大到小排序,设 \(i\) 的排名为 \(rk_i\),那么最坏情况下取 \(i\) 这个元素的条件是 在 \(S\) 中抽了 \(rk_i\) 次(如果超过 \(rk_i\) ,那么之前一定抽到了比 \(f[i]\) 更小的)

因此,在所有情况下求最小值就是答案

复杂度 \(O(能过)\)

#include<bits/stdc++.h>
#define REP(i,a,b) for(int i(a);i<=(b);++i)
using namespace std;
template<typename T,typename U>inline char smin(T&x,const U&y){return x>y?x=y,1:0;}
namespace IOManager{
const unsigned int iSize(131072);
char buf[iSize],*iT=buf+iSize,*iS=iT-1;
struct FastIO{
inline char gc(){
if(++iS==iT)fread(iS=buf,1,iSize,stdin);return *iS;
}
template<typename T>
inline void read(T&w){register char c,p=0;
while(isspace(c=gc()));if(c=='-')p=1,c=gc();w=c^48u;
while(isdigit(c=gc()))w=w*10+(c^48u);if(p)w=-w;
}
inline int read(){register int x;return read(x),x;} };
}IOManager::FastIO io;
#define read io.read
const int n=read(),N=5e5+5;
vector<int>g[N];
int cnt[N],fi[N],se[N],a[N];
int main(){
int ans=1e9;
memset(fi,0x3f,sizeof fi);
REP(i,1,n){
int k=read(),s;
g[i].resize(k);
for(int&x:g[i])x=read();
sort(g[i].begin(),g[i].end());
g[i].resize(s=unique(g[i].begin(),g[i].end())-g[i].begin());
if(s<k)smin(ans,s+1);
for(int x:g[i]){
if(s<fi[x])se[x]=fi[x],fi[x]=s;
else if(s<se[x])se[x]=s;
}
}
REP(i,1,n){
const int s=g[i].size();int k=0;
for(int x:g[i])a[++k]=s==fi[x]?se[x]:fi[x];
sort(a+1,a+1+k,greater<int>());
REP(j,1,k)smin(ans,j+a[j]);
}
cout<<(ans==1e9?-1:ans);
return 0;
}

[NOI.AC#40]Erlang的更多相关文章

  1. NOI.ac #31 MST DP、哈希

    题目传送门:http://noi.ac/problem/31 一道思路好题考虑模拟$Kruskal$的加边方式,然后能够发现非最小生成树边只能在一个已经由边权更小的边连成的连通块中,而树边一定会让两个 ...

  2. NOI.AC NOIP模拟赛 第四场 补记

    NOI.AC NOIP模拟赛 第四场 补记 子图 题目大意: 一张\(n(n\le5\times10^5)\)个点,\(m(m\le5\times10^5)\)条边的无向图.删去第\(i\)条边需要\ ...

  3. # NOI.AC省选赛 第五场T1 子集,与&最大值

    NOI.AC省选赛 第五场T1 A. Mas的童年 题目链接 http://noi.ac/problem/309 思路 0x00 \(n^2\)的暴力挺简单的. ans=max(ans,xor[j-1 ...

  4. NOI.AC NOIP模拟赛 第五场 游记

    NOI.AC NOIP模拟赛 第五场 游记 count 题目大意: 长度为\(n+1(n\le10^5)\)的序列\(A\),其中的每个数都是不大于\(n\)的正整数,且\(n\)以内每个正整数至少出 ...

  5. NOI.AC NOIP模拟赛 第六场 游记

    NOI.AC NOIP模拟赛 第六场 游记 queen 题目大意: 在一个\(n\times n(n\le10^5)\)的棋盘上,放有\(m(m\le10^5)\)个皇后,其中每一个皇后都可以向上.下 ...

  6. NOI.AC NOIP模拟赛 第二场 补记

    NOI.AC NOIP模拟赛 第二场 补记 palindrome 题目大意: 同[CEOI2017]Palindromic Partitions string 同[TC11326]Impossible ...

  7. NOI.AC NOIP模拟赛 第一场 补记

    NOI.AC NOIP模拟赛 第一场 补记 candy 题目大意: 有两个超市,每个超市有\(n(n\le10^5)\)个糖,每个糖\(W\)元.每颗糖有一个愉悦度,其中,第一家商店中的第\(i\)颗 ...

  8. NOI.AC NOIP模拟赛 第三场 补记

    NOI.AC NOIP模拟赛 第三场 补记 列队 题目大意: 给定一个\(n\times m(n,m\le1000)\)的矩阵,每个格子上有一个数\(w_{i,j}\).保证\(w_{i,j}\)互不 ...

  9. NOI.AC WC模拟赛

    4C(容斥) http://noi.ac/contest/56/problem/25 同时交换一行或一列对答案显然没有影响,于是将行列均从大到小排序,每次处理限制相同的一段行列(呈一个L形). 问题变 ...

随机推荐

  1. Unity 设置窗体透明

    设置窗口透明.窗口置顶.鼠标穿透    方法一. 缺点:边缘不平滑,有毛边 参考博客: 1.https://alastaira.wordpress.com/2015/06/15/creating-wi ...

  2. 【Henu ACM Round#20 A】 Fancy Fence

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 看看有没有(n-2)*180/n等于输入的a就好. [代码] #include <bits/stdc++.h> usin ...

  3. 怎样给UINavigationBar加入button?

    Mads Mobæk:给UINavigationBar加入button的演示样例代码 1 2 3 4 5 6 7 8 UIBarButtonItem *rightButton = [[UIBarBut ...

  4. RvmTranslator6.6 - RVM to CATIA

    RvmTranslator6.6 - RVM to CATIA eryar@163.com RvmTranslator can translate the RVM file exported by A ...

  5. php 读取windows 的系统版本,硬盘,内存,网卡,数据流量等

    php 读取windows 的系统版本,硬盘,内存,网卡,数据流量等 <?php header("Content-type: text/html; charset=utf-8" ...

  6. 今天了解了些redis和memcached的知识

    提取于http://www.cnblogs.com/wupeiqi/articles/5132791.html 感谢博主 使用Redis有哪些好处? (1) 速度快,因为数据存在内存中,类似于Hash ...

  7. Programming Languages - Coursera 整理

    找到并学习这门课的原因: 想要学习 functional programming Week1 Introduction and Course-Wide Information week1 很轻松, 主 ...

  8. 暑假集训-WHUST 2015 Summer Contest #0.2

    ID Origin Title 10 / 55 Problem A Gym 100625A Administrative Difficulties   4 / 6 Problem B Gym 1006 ...

  9. Zookeeper的单节点集群详细启动步骤

    这个很简单,见如下博客. 1 week110的zookeeper的安装 + zookeeper提供少量数据的存储 [hadoop@weekend110 zookeeper-3.4.6]$ pwd/ho ...

  10. Python(九) Python的高级语法与用法

    本章节我们揭开Python进阶部分的高级特性,详细讲解枚举.闭包,并对函数式编程做出介绍 一. 枚举其实是一个类 from enum import Enum #枚举类 class VIP(Enum): ...