cf#334-B - More Cowbell-二分
来源:互联网 发布:软件开发维护招聘 编辑:程序博客网 时间:2024/06/15 14:18
http://codeforces.com/contest/604/problem/B
题意:
给n个东西,每个的大小为a[i], 要求要用k个盒子装下所有东西, 每个盒子至多装2个东西,盒子装下东西的前提是。东西的大小之和不超过盒子的大小。
k个盒子的大小一致
求一个最小的盒子size。使得满足题目条件:k个min——size的盒子装下n个东西。
二分盒子的size,下界 a[n],上界 2e7 。
nlogn
#include <cstdio>#include <cmath>#include <cstring>#include <string>#include <algorithm>#include <queue>#include <map>#include <set>#include <vector>#include <iostream>using namespace std; int tm[1000005];int n,k;int bin(int x)<span style="white-space:pre"></span>//判断x个盒子能不能装下所有cowball{//if (x<n/2) return 0;if (x<tm[n]) return 0;int i=1;int j=n;int tmp=k;while (tmp--){int tmpx=x;tmpx-=tm[j];j--;if (tmpx>=tm[i]) i++;if (i>j) break;}if (i>j) return 1;return 0;}int main(){ int i;scanf("%d%d",&n,&k);for(i=1;i<=n;i++){scanf("%d",&tm[i]); }int l=tm[n];int r=2e7;int m;int ans=-1;while(l<=r){if (r-l<=1){if (bin(l))ans=l;elseans=r;break;}m=(l+r)>>1;if (bin(m))r=m;elsel=m+1;}printf("%d\n",ans) ; return 0;}
0 0
- cf#334-B - More Cowbell-二分
- Codeforces Round #334 B. More Cowbell (二分 + 贪心)
- Codeforces Round #334 (Div. 2)B. More Cowbell(二分+贪心)
- codeforces 604B More Cowbell
- Codeforces 604B:More Cowbell
- codeforces B - More Cowbell (贪心)
- CodeForces 604B More Cowbell
- CodeForces 604B More Cowbell
- Codeforces Round #334 (Div. 2) 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 (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 (贪心)
- python在Windows环境下如何快速安装 各类包
- c语言。利用交换概览把值从大到小输出
- 使用git开发最常用命令和操作
- 千里码
- 腾讯云一些命令记录
- cf#334-B - More Cowbell-二分
- jQuery18(小广告效果,动态创建表格)
- bzoj1050【HAOI2006】旅行comf
- jQuery19(无刷新评论,清空元素)
- 一个前端报表设计器的设计分析
- [ShellExtension]图标扩展-IShellIconlayIdentifier实现
- 数据案例-蓝米手机的精准广告营销
- Flash Builder4.7安装
- 比赛和学习需要,开始网联网方向,很多都不懂,希望自己一步一个脚印,坚持不懈的走下去