CodeForces Round #521 (Div.3) D. Cutting Out
http://codeforces.com/contest/1077/problem/D
You are given an array ss consisting of nn integers.
You have to find any array tt of length kk such that you can cut out maximum number of copies of array tt from array ss.
Cutting out the copy of tt means that for each element titi of array tt you have to find titi in ss and remove it from ss. If for some titi you cannot find such element in ss, then you cannot cut out one more copy of tt. The both arrays can contain duplicate elements.
For example, if s=[1,2,3,2,4,3,1]s=[1,2,3,2,4,3,1] and k=3k=3 then one of the possible answers is t=[1,2,3]t=[1,2,3]. This array tt can be cut out 22 times.
- To cut out the first copy of tt you can use the elements [1,2––,3,2,4,3––,1––][1,2_,3,2,4,3_,1_] (use the highlighted elements). After cutting out the first copy of tt the array ss can look like [1,3,2,4][1,3,2,4].
- To cut out the second copy of tt you can use the elements [1––,3––,2––,4][1_,3_,2_,4]. After cutting out the second copy of tt the array ss will be [4][4].
Your task is to find such array tt that you can cut out the copy of tt from ss maximum number of times. If there are multiple answers, you may choose any of them.
The first line of the input contains two integers nn and kk (1≤k≤n≤2⋅1051≤k≤n≤2⋅105) — the number of elements in ss and the desired number of elements in tt, respectively.
The second line of the input contains exactly nn integers s1,s2,…,sns1,s2,…,sn (1≤si≤2⋅1051≤si≤2⋅105).
Print kk integers — the elements of array tt such that you can cut out maximum possible number of copies of this array from ss. If there are multiple answers, print any of them. The required array tt can contain duplicate elements. All the elements of tt (t1,t2,…,tkt1,t2,…,tk) should satisfy the following condition: 1≤ti≤2⋅1051≤ti≤2⋅105.
7 3
1 2 3 2 4 3 1
1 2 3
10 4
1 3 1 3 10 3 7 7 12 3
7 3 1 3
15 2
1 2 1 1 1 2 1 1 2 1 2 1 1 1 1
1 1
The first example is described in the problem statement.
In the second example the only answer is [7,3,1,3][7,3,1,3] and any its permutations. It can be shown that you cannot choose any other array such that the maximum number of copies you can cut out would be equal to 22.
In the third example the array tt can be cut out 55 times.
代码:
#include <bits/stdc++.h>
using namespace std; const int maxn = 2e5 + 10;
int n, k;
int a[maxn];
int times[maxn]; bool can(int x) {
int cnt = 0;
for(int i = 1; i < maxn; i ++)
cnt += times[i] / x;
if(cnt >= k) return true;
return false;
} int main() {
memset(times, 0, sizeof(times));
scanf("%d%d", &n, &k);
for(int i = 1; i <= n; i ++) {
scanf("%d", &a[i]);
times[a[i]] ++;
} int l = 1, r = n, mid, maxx = 1;
while(l <= r) {
mid = (r - l) / 2 + l;
if(can(mid)) maxx = mid, l = mid + 1;
else r = mid - 1;
} int ans[maxn];
int rec = 0;
for(int i = 1; i < maxn; i ++) {
if(times[i] >= maxx)
for(int j = 1; j <= times[i] / maxx; j ++) {
ans[rec ++] = i;
if(rec == k) break;
}
} for(int i = 0; i < k; i ++) {
printf("%d", ans[i]);
printf("%s", i != k - 1 ? " " : "\n");
}
return 0;
}
今天是丧气的一天
CodeForces Round #521 (Div.3) D. Cutting Out的更多相关文章
- Codeforces Round #521 (Div. 3) D. Cutting Out 【二分+排序】
任意门:http://codeforces.com/contest/1077/problem/D D. Cutting Out time limit per test 3 seconds memory ...
- Codeforces Round #521 (Div. 3) E. Thematic Contests(思维)
Codeforces Round #521 (Div. 3) E. Thematic Contests 题目传送门 题意: 现在有n个题目,每种题目有自己的类型要举办一次考试,考试的原则是每天只有一 ...
- CodeForces Round #521 (Div.3) E. Thematic Contests
http://codeforces.com/contest/1077/problem/E output standard output Polycarp has prepared nn competi ...
- Codeforces Round #521 (Div. 3) F1. Pictures with Kittens (easy version)
F1. Pictures with Kittens (easy version) 题目链接:https://codeforces.com/contest/1077/problem/F1 题意: 给出n ...
- CodeForces Round #521 (Div.3) B. Disturbed People
http://codeforces.com/contest/1077/problem/B There is a house with nn flats situated on the main str ...
- CodeForces Round #521 (Div.3) A. Frog Jumping
http://codeforces.com/contest/1077/problem/A A frog is currently at the point 00 on a coordinate axi ...
- Codeforces Round #521 (Div.3)题解
A过水,不讲 题解 CF1077B [Disturbed People] 这题就是个显而易见的贪心可是我考场上差点没想出来 显然把一户被打扰的人家的右边人家的灯关掉肯定比把左边的灯关掉 从左到右扫一遍 ...
- Codeforces Round #521 (Div. 3)
B 题过的有些牵强,浪费了很多时间,这种题一定想好思路和边界条件再打,争取一发过. D 题最开始读错题,后面最后发现可以重复感觉就没法做了,现在想来,数据量大,但是数据范围小枚举不行,二分还是可以的 ...
- Codeforces Round #521 Div. 3 玩耍记
A:签到. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> ...
随机推荐
- Spring框架中的IOC?
Spring中的org.springframework.beans包和org.SpringframeWork.context包构成了Spring框架IOC容器的基础.BeanFactory接口提供了一 ...
- spring mvc 数据绑定入门
1:基本数据类型key 是必传的并且必须类型一致 // http://localhost:8080/bind/baseType.do?xage=10 @RequestMapping(value = & ...
- @font-face css3自定义个性化字体
使用第三方平台转换字体文件为font-face所支持的格式. TureTpe(.ttf)格式 支持浏览器:IE9+,Firefox3.5+,Chrome4+,Safari3+,Opera10+,iOS ...
- jquery mobile 移动web(6)
jquery mobile 针对移动端设备的事件类型. 1.touch 事件. tap 快速触摸屏幕并且离开,类似一种完整的点击操作. taphold 触摸屏幕并保持一段时间. swipe 在1秒内水 ...
- 调用微信JS上传照片接口上传图片
public ActionResult UploadImge(string serverId) { var headPath = "/UploadImage/" + DateTim ...
- ABAP术语-Lock Argument
Lock Argument 原文:http://www.cnblogs.com/qiangsheng/archive/2008/02/29/1085717.html Locked fields in ...
- python运算符及优先级顺序
python语言是一门脚本语言,支持面向对象.面向过程编程,兼具编译性和解释性的动态语言,整理出学习过程中一些基本Python运算符和运算符的优先级顺序. 一.算术运算符 运算符 描述 + 加 - 两 ...
- 如何理解NaN?
NaN这个特殊的Number与所有其他值都不相等,包括它自己: NaN===NaN: //false 唯一能判断NaN的方法是通过isNaN()函数: isNaN(NaN); //tr ...
- Axure RP Extension for Chrome安装
Axure RP Extension for Chrome安装 Axure RP Extension for Chrome是一款谷歌插件,主要可以用来查看原型文件.以前安装插件的时候总是找半天资源,很 ...
- Lavavel5.5源代码 - Pipeline
<?php class Pipeline { protected $passable; protected $pipes = []; protected $method = 'handle'; ...