题意是给你n个数字的序列,让你从中找含k个数字的序列,要求这k个数字要尽可能多次的从n个数字的序列中减去。
解法就是从1到n,二分查找可以删除的最大次数。
http://codeforces.com/contest/1077/problem/D
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+;
int book[maxn];
int box[maxn];
int n,k;
int fun(int cnt)
{
int top=;
for(int i=; i<maxn; i++)
{
for(int j=; j<=book[i]/cnt; j++)
{
box[++top]=i;
}
}
return top;
}
int main()
{
scanf("%d%d", &n, &k);
for(int i=; i<=n; i++)
{
int t;
scanf("%d", &t);
book[t]++;
}
int l,r;
l=,r=n;
while(l<=r)
{
int mid=(l+r)/;
if(fun(mid)>=k)
l=mid+;
else
r=mid-;
}
fun(l-);
printf("%d", box[]);
for(int i=; i<=k; i++)
printf(" %d", box[i]);
}