LightOJ 1076 - Get the Containers
来源:互联网 发布:adobe cc 2017 mac破解 编辑:程序博客网 时间:2024/06/18 07:35
题意:
有n个输奶管,内有一定牛奶,用m个存储罐装这些牛奶,不能分开装,多个管内的奶可以一起装,但一起是需按照顺序装,求满足的n个罐子中的最小容积。
思路:
确定号区间 的左右两边值后,二分搜索该区间内的值,满足则缩小范围,不满足则扩大范围,直到确定出最小值。
代码:
#include <stdio.h> int num[1500];int n, m;int judge(int x){ int sum = 0, count = 1; for (int i = 0; i < n; i++) { sum += num[i]; if (sum > x) sum = num[i], count++; } return count > m?1:0;}int main() {int Case,index; scanf("%d", &Case); while (Case--) { scanf("%d %d", &n, &m); int l = 0, r = 0; for (int i = 0; i < n; i++) {scanf("%d", &num[i]);if (num[i] > l) l = num[i];r += num[i]; } while (r > l) { int mid = (r + l) / 2; if (judge(mid)) l = mid + 1; else r = mid; } printf("Case %d: %d\n", ++index, r); } return 0;}
0 0
- LightOJ 1076 - Get the Containers
- LightOJ 1076 Get the Containers
- LightOJ - 1076 Get the Containers(二分)
- lightoj 1076 - Get the Containers 二分答案
- lightoj 1076 - Get the Containers 【二分 + 贪心】
- LightOJ - 1076 Get the Containers (二分)模板题
- LightOJ--1076--Get the Containers(二分好题)
- LightOJ 1076 Get the Containers(二分经典)
- LIghtOJ 1076 - Get the Containers(二分逼近)
- 【Light】[1076 ]Get the Containers
- light oj 1076 - Get the Containers
- Get the Containers
- Get the Containers
- lightoj1076 Get the Containers 二分
- light1076Get the Containers
- UVa 11413 - Fill the Containers
- Containers
- The Standard Containers as Class Templates
- expect
- python序列通用操作符
- DP------Climbing Stairs
- hbase的rowkey简单设计
- python3.5模拟登陆
- LightOJ 1076 - Get the Containers
- Java 关键字—— static 与 final
- 360 软件误报 与流氓战斗到底
- ListView禁止item被点击
- 【HTML5 未完】HTML5之元素与标签结构--慕课网【学习总结】
- 合并 hdfs 文件
- 2015年第六届蓝桥杯C/C++程序设计本科B组省赛 三羊献瑞(结果填空)
- [Leetcode]97. Interleaving String @python
- php 数组元素快速去重