codeforces 604B More Cowbell
来源:互联网 发布:微信一键删好友软件 编辑:程序博客网 时间:2024/04/30 19:21
题意:给定一个n和一个k,满足(1 ≤ n ≤ 2·k ≤ 100 000),然后给你n个数,按照不递减排列的,这里的k表示的是箱子的个数,你需要把这n个数装到k个箱子里面,一个箱子最多装两个数,这两个数的和就是箱子的容量。最后求箱子的最小容量时多少。
这个题有点坑,首先我们要考虑一下k>n的情况哈,那么就是n个数的最后一个数就是箱子的容量。
然后注意:
我们是不是想把小的尽量和小的组合放在一个箱子里面?
那么你就出错了哈,当时我就是靠这组数据去HACK的别人
4 2
1 2 3 5
如果你按照小的和小的组合,那么答案就是8
正确答案应该是6
然后你就会说那么就是小的和大的组合在一起。
那么你看这组数据:
5 3
1 1 2 2 8
你如果让小的和大的组合在一起,答案就是9
其实答案是8
不废话了,希望想想。
#include<bits/stdc++.h>using namespace std;long long a[100005];int main(){ int n,k; while(~scanf("%d%d",&n,&k)) { long long mm=-1; for(int i=0; i<n; i++) { scanf("%lld",&a[i]); mm=max(mm,a[i]); } int i,j; if(2*k==n)//如果是刚好两倍的情况,那么就是大的和小的组合 { i=0; j=n-1; for(int i=0;i<n/2;i++) { mm=max(mm,a[i]+a[j--]); } } else//否则的话就应该用多出的箱子把当前最大的数字装了,然后再小的和大的组合,贪心的思想 { j=n; int cnt=n-k; int cc=n-cnt*2; while(cc--) { j--; } for(i=0;i<cnt;i++) { mm=max(mm,a[i]+a[--j]); } } printf("%lld\n",mm); }}
0 0
- codeforces 604B More Cowbell
- Codeforces 604B:More Cowbell
- CodeForces 604B More Cowbell
- CodeForces 604B More Cowbell
- codeforces-604B More Cowbell(贪心)
- 【31.72%】【codeforces 604B】More Cowbell
- CodeForces 604 B.More Cowbell(贪心)
- codeforces B - More Cowbell (贪心)
- Codeforces Round #334 (604B) More Cowbell [贪心]
- Codeforces Round #334 (Div. 2) B. More Cowbell
- Codeforces Round #334 (Div. 2) B. More Cowbell
- Codeforces Round #334 B. More Cowbell (二分 + 贪心)
- Codeforces Round #334 (Div. 2) B. More Cowbell
- Codeforces Round #334 (Div. 2) B. More Cowbell
- Codeforces Round #334 (Div. 2) B. More Cowbell
- Codeforces Round #334 (Div. 2) B. More Cowbell
- Codeforces Round #334 (Div. 2) B. More Cowbell (贪心)
- Codeforces Round #334 (Div. 2) B. More Cowbell
- 黑马程序员_继承
- Trace Failed Requests <traceFailedRequests>
- How to Enable Failed Request Tracing for UNC Hosting
- debian-纯文本行下和图形下-分辨率设置
- IIS: Cannot Write Configuration File due to Insufficient Permissions
- codeforces 604B More Cowbell
- 黑马程序员_继承中子父类的实例化过程
- debian8-my-cmd-history.log
- MATLAB链接MinGW编译器
- c++游戏中接入lua脚本系统
- OpenGL ES 2.0渲染管线
- android中setClickable,setEnabled,setFocusable的含义及区别
- Get IIS Errors Into Elastic
- cocos2dx3.x绘制自己的node