LightOJ - 1076 Get the Containers(二分)
来源:互联网 发布:好的外文数据库 编辑:程序博客网 时间:2024/06/06 10:04
题目大意:给你N个数字,要起将这N个数字划分成K个区间,并要求每个区间的和的最大值最小
解题思路:最大值最小问题,二分解决
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef long long LL;const int N = 1000010;LL v[N];LL l, r;int n, m, cas = 1;void init() { scanf("%d%d", &n, &m); l = r = 0; for (int i = 0; i < n; i++) { scanf("%lld", &v[i]); l = max(v[i], l); r += v[i]; } v[n] = 0;}bool judge(LL mid) { LL sum = 0; int num = 1; for (int i = 0; i <= n; i++) { if (sum + v[i] > mid) { sum = v[i]; num++; } else sum += v[i]; } return num <= m;}void solve() { while (l <= r) { LL mid = (l + r) >> 1; if (judge(mid)) r = mid - 1; else l = mid + 1; } printf("Case %d: %lld\n", cas++, r + 1);}int main() { int test; scanf("%d", &test); while (test--) { init(); solve(); } 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
- lightoj1076 Get the Containers 二分
- 【Light】[1076 ]Get the Containers
- light oj 1076 - Get the Containers
- Get the Containers
- Get the Containers
- light1076Get the Containers
- lightoj 1304 The Best Contest Site Ever (二分匹配)
- UVa 11413 - Fill the Containers
- lightoj 1425 - The Monkey and the Oiled Bamboo 二分答案or乱搞
- 14 Longest Common Prefix
- LightOJ - 1048 Conquering Keokradong(贪心)
- 监督学习(机器学习)
- OnItemClickListener与OnScrollListener监听器
- 树形dp题集之树的直径
- LightOJ - 1076 Get the Containers(二分)
- JAVA中3大集合框架队列的使用
- cocos2d-x设计模式发掘之二:二段构建模式
- Spark到底解决了什么根本性的技术问题?
- Windows多线程编程困惑
- 【Matlab开发】matlab中norm范数以及向量点积、绘图设置相关
- java中的抽象类
- U盘无法安装win10提示Your PC/Device needs to be repaired
- cocos2d-x设计模式发掘之三:管理者模式