码迷,mamicode.com
首页 > 其他好文 > 详细

D. Cutting Out 二分

时间:2018-11-18 17:27:56      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:its   clu   nbsp   targe   ORC   题目   数字   can   要求   

题意是给你n个数字的序列,让你从中找含k个数字的序列,要求这k个数字要尽可能多次的从n个数字的序列中减去。

解法就是从1到n,二分查找可以删除的最大次数。

http://codeforces.com/contest/1077/problem/D

#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
int book[maxn];
int box[maxn];
int n,k;
int fun(int cnt)
{
    int top=0;
    for(int i=1; i<maxn; i++)
    {
        for(int j=1; j<=book[i]/cnt; j++)
        {
            box[++top]=i;
        }
    }
    return top;
}
int main()
{
    scanf("%d%d", &n, &k);
    for(int i=1; i<=n; i++)
    {
        int t;
        scanf("%d", &t);
        book[t]++;
    }
    int l,r;
    l=1,r=n;
    while(l<=r)
    {
        int mid=(l+r)/2;
        if(fun(mid)>=k)
            l=mid+1;
        else
            r=mid-1;
    }
    fun(l-1);
    printf("%d", box[1]);
    for(int i=2; i<=k; i++)
        printf(" %d", box[i]);
}

 

D. Cutting Out 二分

标签:its   clu   nbsp   targe   ORC   题目   数字   can   要求   

原文地址:https://www.cnblogs.com/dongdong25800/p/9978457.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!