codeforces 540 B School Marks【贪心】
题意:一共n个数,给出其中k个数,要求这n个数的中位数为y,这n个数的和不超过x,补全剩下的n-k个数
先统计给出的k个数里面比中位数小的数,
如果cnt<=n/2,说明中位数还没有出现,把这n/2-cnt个数都补上1,剩下的都补上y
如果cnt>n/2,说明中位数不存在
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std; #define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i) typedef long long LL;
const int INF = (<<)-;
const int mod=;
const int maxn=; int a[maxn]; int main(){
int n,k,p,x,y;
cin>>n>>k>>p>>x>>y;
int ans=;
int sum=;
for(int i=;i<=k;i++){
cin>>a[i];
sum+=a[i];
if(a[i]<y) ans++;
}
int l,r; if(ans<=n/){
l=min(n/-ans,n-k);
r=n-l-k;
sum+=l+r*y; if(sum>x) printf("-1\n");
else{
for(int i=;i<=l;i++) printf("1 ");
for(int i=;i<=r;i++) printf("%d ",y);
printf("\n");
}
}
else printf("-1\n");
return ;
}
g0---oooooooooo
codeforces 540 B School Marks【贪心】的更多相关文章
- codeforces Gym 100338E Numbers (贪心,实现)
题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...
- [Codeforces 1214A]Optimal Currency Exchange(贪心)
[Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的 ...
- (CodeForces )540B School Marks 贪心 (中位数)
Little Vova studies programming to p. Vova is very smart and he can write every test for any mark, b ...
- CodeForces - 540B School Marks —— 贪心
题目链接:https://vjudge.net/contest/226823#problem/B Little Vova studies programming in an elite school. ...
- CodeForces 540
A. Combination Lock time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- codeforces 349B Color the Fence 贪心,思维
1.codeforces 349B Color the Fence 2.链接:http://codeforces.com/problemset/problem/349/B 3.总结: 刷栅栏.1 ...
- Codeforces Gym 100269E Energy Tycoon 贪心
题目链接:http://codeforces.com/gym/100269/attachments 题意: 有长度为n个格子,你有两种操作,1是放一个长度为1的东西上去,2是放一个长度为2的东西上去 ...
- CodeForces 797C Minimal string:贪心+模拟
题目链接:http://codeforces.com/problemset/problem/797/C 题意: 给你一个非空字符串s,空字符串t和u.有两种操作:(1)把s的首字符取出并添加到t的末尾 ...
- codeforces 803D Magazine Ad(二分+贪心)
Magazine Ad 题目链接:http://codeforces.com/contest/803/problem/D ——每天在线,欢迎留言谈论. 题目大意: 给你一个数字k,和一行字符 例: g ...
随机推荐
- bzoj1202: [HNOI2005]狡猾的商人(差分约束)
1202: [HNOI2005]狡猾的商人 题目:传送门 题解: 据说是带权并查集!蒟蒻不会啊!!! 可是听说lxj大佬用差分约束A了,于是开始一通乱搞. 设s[i]为前i个月的总收益,那么很容易就可 ...
- Spark Streaming 总结
这篇文章记录我使用 Spark Streaming 进行 ETL 处理的总结,主要包含如何编程,以及遇到的问题. 环境 我在公司使用的环境如下: Spark: 2.2.0 Kakfa: 0.10.1 ...
- 三级联动(ajax同步)
html <div id="frame"></div> js $(function(){ //拼接省市区下拉框 var str = `<select ...
- String Comparison(C#)
When comparing programmatic strings, you should always use StringComparison.Ordinal or StringCompari ...
- IE6 css fixed
.fixed-top{position:fixed;bottom:auto;top:0px;} .fixed-bottom{position:fixed;bottom:0px;top:auto;} . ...
- STM8S103之GPIO
如何快速了解GPIO,查看Reference manual中GPIO章节,初步了解到GPIO GPIO输入分为:Floating Input和Input with pull-up GPIO输出分为:O ...
- 壹、js的概述
一.js的起源 1992年的时候,一家名为Nomnas的公司开发出了c减减的嵌入式脚本语言:然后利用分享的方式,扩大其市场. 之后,Netscape为了扩展浏览器的功能,开发了一个名为LiveScri ...
- ajax同时提交表单且包含文件
说明一下:FormData对象是html5的一个对象,目前的一些主流的浏览器都已经兼容.ie8暂时不支持,不支持FormData的,可以使用方法二,下面会介绍.接着说FormData,它是一个html ...
- vue中的methods、computed和watch
1.computed属性: 经过处理返回的数据值,只要源数据没有发生改变,computed函数里面对相应的数据就不会反生改变,相当于缓存在本地;发生改变的时候,computed对应数据的函数才会发生改 ...
- spring中IOC的简单使用
spring的ioc主要就是依赖注入,有基于构造器的依赖注入还有通过设值注入,这里我只简单的实现设值注入的方法,通过spring的依赖管理,我们可以很方便的了解各层之间的依赖关系,降低了各层之间的耦合 ...