light oj 1076 - Get the Containers
来源:互联网 发布:360水滴破解软件 编辑:程序博客网 时间:2024/06/09 19:15
K - Get the Containers
Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu
Submit
Status
Practice
LightOJ 1076
Description
A conveyor belt has a number of vessels of different capacities each filled to brim with milk. The milk from conveyor belt is to be filled into 'm' containers. The constraints are:
1. Whenever milk from a vessel is poured into a container, the milk in the vessel must be completely poured into that container only. That is milk from same vessel cannot be poured into different containers.
2. The milk from the vessel must be poured into the container in order which they appear in the conveyor belt. That is, you cannot randomly pick up a vessel from the conveyor belt and fill the container.
3. The ith container must be filled with milk only from those vessels that appear earlier to those that fill jth container, for all i < j.
Given the number of containers m, you have to fill the containers with milk from all the vessels, without leaving any milk in the vessel. The containers need not necessarily have same capacity. You are given the liberty to assign any possible capacities to them. Your job is to find out the minimal possible capacity of the container which has maximal capacity.
Input
Input starts with an integer T (≤ 100), denoting the number of test cases.
Each case contains two integers n (1 ≤ n ≤ 1000), the number of vessels in the conveyor belt and then m (1 ≤ m ≤ 106), which specifies the number of containers to which you have to transfer the milk. The next line contains the capacity c (1 ≤ c ≤ 106) of each vessel in order which they appear in the conveyor belt. Note that, milk is filled to the brim of any vessel. So the capacity of the vessel is equal to the amount of milk in it.
Output
For each case, print the case number and the desired result. See the samples for exact formatting.
Sample Input
2
5 3
1 2 3 4 5
3 2
4 78 9
Sample Output
Case 1: 6
Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu
Submit
Status
Practice
LightOJ 1076
Description
A conveyor belt has a number of vessels of different capacities each filled to brim with milk. The milk from conveyor belt is to be filled into 'm' containers. The constraints are:
1. Whenever milk from a vessel is poured into a container, the milk in the vessel must be completely poured into that container only. That is milk from same vessel cannot be poured into different containers.
2. The milk from the vessel must be poured into the container in order which they appear in the conveyor belt. That is, you cannot randomly pick up a vessel from the conveyor belt and fill the container.
3. The ith container must be filled with milk only from those vessels that appear earlier to those that fill jth container, for all i < j.
Given the number of containers m, you have to fill the containers with milk from all the vessels, without leaving any milk in the vessel. The containers need not necessarily have same capacity. You are given the liberty to assign any possible capacities to them. Your job is to find out the minimal possible capacity of the container which has maximal capacity.
Input
Input starts with an integer T (≤ 100), denoting the number of test cases.
Each case contains two integers n (1 ≤ n ≤ 1000), the number of vessels in the conveyor belt and then m (1 ≤ m ≤ 106), which specifies the number of containers to which you have to transfer the milk. The next line contains the capacity c (1 ≤ c ≤ 106) of each vessel in order which they appear in the conveyor belt. Note that, milk is filled to the brim of any vessel. So the capacity of the vessel is equal to the amount of milk in it.
Output
For each case, print the case number and the desired result. See the samples for exact formatting.
Sample Input
2
5 3
1 2 3 4 5
3 2
4 78 9
Sample Output
Case 1: 6
Case 2: 82
二分比较,,,,,
代码:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int n,m,shu[1050];int zhao(int xx){bool fafe=true;int s=0,ge=1;for (int i=1;i<=n;i++){if (s+shu[i]>xx){ge++;s=shu[i];}elses+=shu[i];}if (ge<=m) return true;else return false;}int main(){int t;scanf("%d",&t);for (int ca=1;ca<=t;ca++){scanf("%d%d",&n,&m);int le=0,mid,ri=0,ans;for (int i=1;i<=n;i++){scanf("%d",&shu[i]);le=max(le,shu[i]);ri+=shu[i];}while (ri>=le){mid=(ri+le)/2;if (zhao(mid)){ans=mid;ri=mid-1;}else{le=mid+1;}}printf("Case %d: %d\n",ca,ans);}return 0;}
0 0
- light oj 1076 - Get the Containers
- 【Light】[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 【二分 + 贪心】
- Get the Containers
- Get the Containers
- lightoj1076 Get the Containers 二分
- LightOJ - 1076 Get the Containers (二分)模板题
- LightOJ--1076--Get the Containers(二分好题)
- LightOJ 1076 Get the Containers(二分经典)
- LIghtOJ 1076 - Get the Containers(二分逼近)
- light oj 1274 - Beating the Dataset
- light oj
- light oj
- Light OJ
- 反编译流程
- 剑指offer之面试题13:在O(1)时间删除链表节点
- 威佐夫博弈(Wythoff Game)
- GEEK编程练习— —zigzag矩阵
- 菜鸟入门_Python_机器学习(3)_回归
- light oj 1076 - Get the Containers
- Extjs5中HtmlEditor文本编辑器
- Mysql报错注入简单测试模型 20160416
- iOS 和 swift 中常见的 Int、Int8、Int16、Int32和 Int64介绍
- 如何使用VC++6.0发布程序(即release版本程序)
- 动态规划---0-1背包问题
- 检查lfs从内核到到第一个进程init是否成功
- Oil Deposits 深度优先搜素油田
- FragmentTabHost的应用