LightOJ 1076 Get the Containers
2016-04-21 21:15
483 查看
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
Case 2: 82
二分法经典用法。
求一段数分成M组后最大值的最小值。
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
二分法经典用法。
求一段数分成M组后最大值的最小值。
#include<stdio.h> #include<string.h> int a[10001]; int n,m; int Judge(int c) { int count=0; int sum=0; for(int i=0;i<n;i++) { if(sum+a[i]<=c) { sum+=a[i]; } else { sum=a[i]; count++; } } if(count+1>m) return 0; return 1; } int main() { int T; int i,ans,mid; int k=1; scanf("%d",&T); while(T--) { scanf("%d%d",&n,&m); int l,r; r=0;l=0; for(i=0;i<n;i++) { scanf("%d",&a[i]); r+=a[i]; l=l>a[i]?l:a[i]; } while(r>=l) { mid=(r+l)/2; if(Judge(mid)) { ans=mid; r=mid-1; } else { l=mid+1; } } printf("Case %d: %d\n",k++,ans); } return 0; }
相关文章推荐
- 【Light】[1076 ]Get the Containers
- 阶梯博弈(Staircase Nim)
- Dispatcher initialization failed:Unable to load configuration
- light oj 1076 - Get the Containers
- 哈佛大学研究新人工智能系统 速度媲美人类大脑
- HDU 2820 Permutaion
- Fibonacci Again
- POJ3691.DNA repair (Trie图 && DP)
- com.google.android.xts.devicepolicy.DeviceOwnerTest#testFactoryResetProtection fail
- AIDL API级别详细解释
- BZOJ 3172 [Tjoi2013]单词 AC自己主动机(fail树)
- linker command failed with exit code 1 (use -v to see
- ping: unknown host www.baidu.com 最简单的方法
- 严重: StandardServer.await: create[localhost:8005]
- HDU 5319 Painter
- A. Reconnaissance 2
- A. Reconnaissance
- HDU 1839 Delay Constrained Maximum Capacity Path
- HDU1789 Doing Homework again(贪心)
- 爬楼梯的问题Climbing Stairs