题目链接:Cutting Out

题意:给定一个n长度的数字序列s,要求得到一个k长度的数字序列t,每次从s序列中删掉完整的序列t,求出能删次数最多的那个数字序列t。

题解:数字序列s先转换成不重复的数字序列,并记录各个数字重复的次数,然后按照重复次数从大到小排序。二分最大删除次数,最后再输出对应的序列t。

 #include <map>
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std; const int N=2e5+;
int n,k,x,id=;
map <int,int> m;
struct node{
int val,cnt;
}p[N]; bool cmp(node x,node y){
return x.cnt>y.cnt;
} bool check(int mid){
int need=k;
for(int i=;i<=id;i++){
if(need==) return true;
int tmp=p[i].cnt/mid;
if(tmp>=){
if(need>=tmp) need-=tmp;
else return true;
}
else return false;
}
if(need>) return false;
return true;
} int main(){
scanf("%d%d",&n,&k);
for(int i=;i<=n;i++){
scanf("%d",&x);
if(!m[x]) id++,m[x]=id,p[id].val=x;
p[m[x]].cnt++;
}
sort(p+,p++id,cmp);
int l=,r=N,ans=;
while(l<=r){
int mid=(l+r)/;
if(check(mid)) l=mid+,ans=mid;
else r=mid-;
}
for(int i=;i<=id;i++){
if(k==) break;
int tmp=p[i].cnt/ans;
if(tmp>=){
if(k>=tmp){
k-=tmp;
for(int j=;j<=tmp;j++) printf("%d ",p[i].val);
}
else{
for(int j=;j<=k;j++) printf("%d ",p[i].val);
k=;
}
}
}
return ;
}

Codeforces 1077D Cutting Out(二分答案)的更多相关文章

  1. [Codeforces 1199C]MP3(离散化+二分答案)

    [Codeforces 1199C]MP3(离散化+二分答案) 题面 给出一个长度为n的序列\(a_i\)和常数I,定义一次操作[l,r]可以把序列中<l的数全部变成l,>r的数全部变成r ...

  2. Codeforces 772A Voltage Keepsake - 二分答案

    You have n devices that you want to use simultaneously. The i-th device uses ai units of power per s ...

  3. 2018.12.08 codeforces 939E. Maximize!(二分答案)

    传送门 二分答案好题. 题意简述:要求支持动态在一个数列队尾加入一个新的数(保证数列单增),查询所有子数列的 最大值减平均值 的最大值. 然而网上一堆高人是用三分做的. 我们先考虑当前的答案有可能由什 ...

  4. Educational Codeforces Round 21 Problem F (Codeforces 808F) - 最小割 - 二分答案

    Digital collectible card games have become very popular recently. So Vova decided to try one of thes ...

  5. codeforces 1077D Cutting Out 【二分】

    题目:戳这里 题意:给n个数的数组,要求找k个数满足,这k个数在数组中出现的次数最多. 解题思路:k个数每个数出现次数都要最大化,可以想到二分下限,主要是正确的二分不好写. 附ac代码: 1 #inc ...

  6. Codeforces 700A As Fast As Possible(二分答案)

    [题目链接] http://codeforces.com/problemset/problem/700/A [题目大意] 有一辆限载k人速度为v2的车,n个步行速度均为v1的人要通过一段长度为l的距离 ...

  7. Codeforces Round #276 (Div. 1) E. Sign on Fence (二分答案 主席树 区间合并)

    链接:http://codeforces.com/contest/484/problem/E 题意: 给你n个数的,每个数代表高度: 再给出m个询问,每次询问[l,r]区间内连续w个数的最大的最小值: ...

  8. Codeforces Round #425 (Div. 2) Problem C Strange Radiation (Codeforces 832C) - 二分答案 - 数论

    n people are standing on a coordinate axis in points with positive integer coordinates strictly less ...

  9. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答案 - 动态规划

    There are n people and k keys on a straight line. Every person wants to get to the office which is l ...

随机推荐

  1. Neutron server的运行原理(未完待续)

    1.Neutron server首先是一个web server, 对于http和https协议的报文进行响应. 2.Neutron server进程里面包含了一个WSGI 应用程序,以及不同模块的pl ...

  2. iOS----------计算一段代码执行时间

    CFAbsoluteTime start = CFAbsoluteTimeGetCurrent(); //在这写入要计算时间的代码 // do something CFAbsoluteTime end ...

  3. Windows Java包环境变量的设置

    复制Bin文件所在路径 验证

  4. SQL Server Log Shipping学习总结

      SQL Server的日志传送(log shipping)技术一直比较鸡肋,尤其当SQL Server 推出了Always On技术以后,估计使用日志传送(log shipping)这种技术方案的 ...

  5. leaflet动态路径

    在leaflet中使用动态路径需要结合插件使用,对比了好几个插件,最终找到leaflet.motion比较合适: leaflet地址:https://leafletjs.com/ leaflet.mo ...

  6. Asp.net Core应用程序部署为服务

    安装前使用dotnet命令运行下看网站能不能正常运行 1.下载nssm,下载后解压文件 下载地址:https://nssm.cc/usage 2.使用命令行工具进入到nssm的目录: 3.执行服务安装 ...

  7. 本地windows下搭建git的本地服务器

    本地windows下搭建git的本地服务器 准备工作: 本地安装java环境,配置环境变量(略) 下载gitblit文件,百度一大堆 开始第一步: 减压gitblit压缩包到某个目录下,比如我在:H: ...

  8. Vim 宏

    宏的概念 什么是宏呢?英文名:macro,代表一串命令的集合. 示例操作文本 SELECT * FROM `edu_ocr_task` WHERE ((`userId`=284871) AND (`u ...

  9. const int *p;int *const p;区别及用法

    在单片机程序设计中,我们经常会用到const这个关键字,在有些单片机的编译器中可能会是code(比如51系列单片机),但我们在学习C语言的时候,首先还是先学到的const.我们知道,const关键字的 ...

  10. python import详解

    1.import作用 引入模块 2.import的特点 一个程序中,import的模块不会重复被引用,如: # test1.py import test2 print test2.attr # tes ...