codeforces 604B More Cowbell
题目链接:http://codeforces.com/contest/604/problem/B
题意:n个数字,k个盒子,把n个数放入k个盒子中,每个盒子最多只能放两个数字,问盒子容量的最小值是多少
(当时没有看清题意,每个盒子最多只能放入两个数字)n个数字的输入是从小到大
题目分类:贪心
代码:
#include<bits/stdc++.h> using namespace std;
int a[];
int b[]; int main()
{
int n,k;
cin>>n>>k;
for(int i=;i<=n;i++)
{
cin>>a[i];
}
if(n<=k)
{
cout<<a[n]<<endl;
return 0;
}
for(int j=;j<=k;j++) //先把大的放进去
{
b[j]=a[n-j+];
}
sort(b+,b+k+);
n=n-k;
for(int i=1;i<=k&&n>=1;i++) //代码的关键部分
{
b[i]+=a[n];
n--;
}
sort(b+,b+k+);
printf("%d\n",b[k]);
return ;
}
codeforces 604B More Cowbell的更多相关文章
- 【31.72%】【codeforces 604B】More Cowbell
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【CodeForces 604B】F - 一般水的题1-More Cowbe
Description Kevin Sun wants to move his precious collection of n cowbells from Naperthrill to Exeter ...
- codeforce 604B More Cowbell
题意:n个球,分成k堆.问堆的最大值的最小. #include <bits/stdc++.h> typedef long long ll; using namespace std; int ...
- CF 604B More Cowbell#贪心
(- ̄▽ ̄)-* //把最大单独放,然后第二大的和最小的放一起,第三大的和第二小的放一起 //由此类推,求最大值,即为盒的最小值 #include<iostream> #include&l ...
- 「日常训练」More Cowbell(Codeforces Round #334 Div.2 B)
题意与分析(CodeForces 604B) 题意是这样的:\(n\)个数字,\(k\)个盒子,把\(n\)个数放入\(k\)个盒子中,每个盒子最多只能放两个数字,问盒子容量的最小值是多少(水题) 不 ...
- codeforces604B
More Cowbell CodeForces - 604B Kevin Sun wants to move his precious collection of n cowbells from Na ...
- Codeforces Round #334 (Div. 2) B. More Cowbell 二分
B. More Cowbell Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/probl ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
随机推荐
- Android学习笔记:Activity生命周期详解
进行android的开发,必须深入了解Activity的生命周期.而对这个讲述最权威.最好的莫过于google的开发文档了. 本文的讲述主要是对 http://developer.android.co ...
- Windows Azure 网站 (WAWS) 和中间证书
编辑人员注释:本文章由 Windows Azure 网站团队的项目经理 Erez Benari 撰写. 在 Windows Azure 网站上使用 SSL 已经司空见惯.虽然向网站上传和分配证书通常简 ...
- 服务列表 - Sina App Engine
服务列表 - Sina App Engine 短信服务 新浪无线短信服务是由新浪无线提供的综合性短信服务. 使用服务 下载SDK: php 服务首页 方法 新浪无线短信服务是由新浪无线提供的综合性短信 ...
- 用定时器T0查询方式P0口8位控制LED闪烁
#include<reg52.h> #define uchar unsigned char #define uint unsigned int void main (void) { uch ...
- Javascript面向对象研究心得
这段时间正好公司项目须要,须要改动fullcalendar日历插件,有机会深入插件源代码.正好利用这个机会,我也大致学习了下面JS的面向对象编程,感觉收获还是比較多的. 所以写了以下这篇文章希望跟大家 ...
- Swift - 如何实现字符串的HMAC_SHA1加密
前段时间有个网友问是否有Swift的HMAC_SHA1算法.这次就专门写篇相关文章进行介绍.要说明HMAC-SHA1,首先要先了解什么是HMAC,什么是SHA. 1,HMAC(散列消息身份验证码:Ha ...
- linux环境设置:使ftp不输密码
# cd ~; # vi .netrc; Add beloew words, 可以追加多个账户: machine yourservername login yourname password your ...
- C#对数字添加逗号,千分位
/// <summary> /// 对数字添加”,“号,可以处理负数以及带有小数的情况 /// </summary> /// <param name="vers ...
- 使用VS2012主题插件创建自己的主题
上篇文章讲了如何更换VS2012的主题,具体内容请参考:Vistual Studio 2012更换皮肤.可是上面的步骤仅仅让我们可选择的主题是增多了,我们可不可以自己创建自己的主题呢? 答案是肯定的, ...
- db2迁移至oracle过程中的问题
(1)时间日期问题: db2中‘2013-07-17 00:02:55’ oracle中to_date('2013-07-17 00:02:55' , 'YYYY-MM-DD HH24:MI:SI ...