Codeforces 1077D Cutting Out(二分答案)
题目链接: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(二分答案)的更多相关文章
- [Codeforces 1199C]MP3(离散化+二分答案)
[Codeforces 1199C]MP3(离散化+二分答案) 题面 给出一个长度为n的序列\(a_i\)和常数I,定义一次操作[l,r]可以把序列中<l的数全部变成l,>r的数全部变成r ...
- 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 ...
- 2018.12.08 codeforces 939E. Maximize!(二分答案)
传送门 二分答案好题. 题意简述:要求支持动态在一个数列队尾加入一个新的数(保证数列单增),查询所有子数列的 最大值减平均值 的最大值. 然而网上一堆高人是用三分做的. 我们先考虑当前的答案有可能由什 ...
- 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 ...
- codeforces 1077D Cutting Out 【二分】
题目:戳这里 题意:给n个数的数组,要求找k个数满足,这k个数在数组中出现的次数最多. 解题思路:k个数每个数出现次数都要最大化,可以想到二分下限,主要是正确的二分不好写. 附ac代码: 1 #inc ...
- Codeforces 700A As Fast As Possible(二分答案)
[题目链接] http://codeforces.com/problemset/problem/700/A [题目大意] 有一辆限载k人速度为v2的车,n个步行速度均为v1的人要通过一段长度为l的距离 ...
- Codeforces Round #276 (Div. 1) E. Sign on Fence (二分答案 主席树 区间合并)
链接:http://codeforces.com/contest/484/problem/E 题意: 给你n个数的,每个数代表高度: 再给出m个询问,每次询问[l,r]区间内连续w个数的最大的最小值: ...
- 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 ...
- 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 ...
随机推荐
- nodejs 使用 js 模块
nodejs 使用 js 模块 Intro 最近需要用 nodejs 做一个爬虫,Google 有一个 Puppeteer 的项目,可以用它来做爬虫,有关 Puppeteer 的介绍网上也有很多,在这 ...
- Linux下创建桌面快捷方式
建立一个文本文件,文件名必须以.desktop结尾,.desktop前面的作为快捷方式的名称 添加如下内容 [Desktop Entry]Encoding=UTF-8Name=PostmanExec= ...
- net view 提示6118错误 解决方法。
1.win+R ,输入services.msc 开启服务:Server ,WorkStation,computer Browser 2.如果你的电脑没有computer Browser服务,win+R ...
- 生成Csv格式的字符串
using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using Sy ...
- 网络编程 单纯UDP通信
网络编程 单纯UDP通信 1,UDP发送端 2,UDP接收端 UDP发送端: #include <stdio.h> #include <unistd.h> #include & ...
- adb server version doesn’t match this client
上传文件到海马玩模拟器 环境变量:ANDROID_SDK_HOME配置是D:\Android\android_sdk_windows 报错:adb server version (31) doesn' ...
- Linux(Centos7)下搭建SVN服务器 (转载)
系统环境:centos7.2 第一步:通过yum命令安装svnserve,命令如下: yum -y install subversion 此命令会全自动安装svn服务器相关服务和依赖,安装完成会自动停 ...
- java图片上传及图片回显1
目的:选择图片,进行图片回显之后将图片保存到服务器上(PS:没有使用任何插件,样式很丑) 实现方式: js+servlet+jsp的方式来实现 事先准备: 文件上传处理在浏览器中是以流的形式提交到服务 ...
- css实现单行(多行)文本溢出显示 ...
overflow: hidden; text-overflow:ellipsis; white-space: nowrap; 当然还需要加宽度width属来兼容部分浏览. 以上为单行文本溢出===== ...
- Java MultipartFile 使用记录
private void file(String path,MultipartFile file){ String separator = "/"; String originFi ...