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 ...
随机推荐
- QT多线程的使用
今天给大家介绍三种QT里面使用多线程的方法 1.继承QThread并且重写run方法来实现多线程 #ifndef MYQTHREAD_H #define MYQTHREAD_H #include &l ...
- 测者的测试技术笔记:揭开java method的一个秘密--巨型函数
相信,很多人都不知道Java的Method的上限为64K.本文将超过这个上限的函数叫做巨型函数. 巨型函数的问题 1.如果代码超过了这个限制,Java编译器就报"Code too large ...
- 从0开始的Python学习007函数&函数柯里化
简介 函数是可以重用的程序段.首先这段代码有一个名字,然后你可以在你的程序的任何地方使用这个名称来调用这个程序段.这个就是函数调用,在之前的学习中我们已经使用了很多的内置函数像type().range ...
- c/c++ 多线程 一个线程等待某种事件发生
多线程 一个线程等待某种事件发生 背景:某个线程在能够完成其任务之前可能需要等待另一个线程完成其任务. 例如:坐夜间列车,为了能够不坐过站, 1,整夜保持清醒,但是这样你就会非常累,不能够睡觉. 2, ...
- c/c++ linux 进程间通信系列2,使用UNIX_SOCKET
linux 进程间通信系列2,使用UNIX_SOCKET 1,使用stream,实现进程间通信 2,使用DGRAM,实现进程间通信 关键点:使用一个临时的文件,进行信息的互传. s_un.sun_fa ...
- NSTimer 不工作 不调用方法
比如,定义一个NSTimer来隔一会调用某个方法,但这时你在拖动textVIew不放手,主线程就被占用了.timer的监听方法就不调用,直到你松手,这时把timer加到 runloop里,就相当于告诉 ...
- Cmder--Windows下代替原生的cmd命令行工具
Cmder是Windows下的命令行工具,用来代替Windows自带的cmd 官网:http://cmder.net/ 这里下载Full版本 https://github.com/cmderdev/c ...
- Saltstack_使用指南02_远程执行-验证
1. 主机规划 2. Master与哪些minion通信 2.1. Master与哪些minion正常通信 [root@salt100 ~]# salt '*' test.ping salt100: ...
- es crul查询(一)
C:\Users\Administrator>elasticdump --input=D:\test --output=http://localhost:9200/logs_apipki_201 ...
- 读写锁ReentrantReadWriteLock的使用
package com.thread.test.Lock; import java.util.Random; import java.util.concurrent.locks.Lock; impor ...