1076 - Get the Containers
Time Limit: 2 second(s) | Memory Limit: 32 MB |
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:
- 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.
- 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.
- 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 |
Output for Sample Input |
2 5 3 1 2 3 4 5 3 2 4 78 9 |
Case 1: 6 Case 2: 82 |
Note
For the first case, the capacities of the three containers be 6, 4 and 5. So, we can pour milk from the first three vessels to the first container and the rest in other two containers. So, the maximum capacity of the container is 6. Suppose the capacities of the containers be 3, 7 and 5. Then we can also pour the milk, however, the maximum capacity is 7. As we want to find the result, where the maximum capacity is as low as possible; the result is 6.
思路:二分答案;
和昨天那道一样还简单http://www.cnblogs.com/zzuli2sjy/p/5571396.html
1 #include<stdio.h>
2 #include<algorithm>
3 #include<iostream>
4 #include<string.h>
5 #include<queue>
6 #include<stack>
7 #include<set>
8 #include<math.h>
9 using namespace std;
10 int ans[2000];
11 int uu[2000];
12 bool check(int k,int n,int m)
13 {
14 int i,j;
15 int sum=0;
16 int cnt=1;
17 for(i=0; i<n; i++)
18 {
19 if(sum+ans[i]>k)
20 {
21 uu[cnt-1]=sum;
22 sum=ans[i];
23 cnt++;
24 }
25 else if(sum+ans[i]<=k)
26 {
27 sum+=ans[i];
28 }
29 }uu[cnt-1]=sum;
30 if(m>=cnt)
31 return true;
32 else return false;
33 }
34 int main(void)
35 {
36 int i,j,k;
37 int s;
38 scanf("%d",&k);
39 for(s=1; s<=k; s++)
40 { memset(uu,0,sizeof(uu));
41 int n;
42 int m;
43 int maxx=0;
44 int sum=0;
45 scanf("%d %d",&n,&m);
46 for(i=0; i<n; i++)
47 {
48 scanf("%d",&ans[i]);
49 maxx=max(maxx,ans[i]);
50 sum+=ans[i];
51 }
52 int l=maxx;
53 int r=sum;
54 int answer=-1;
55 while(l<=r)
56 {
57 int mid=(l+r)/2;
58 bool us=check(mid,n,m);
59 if(us)
60 {
61 answer=mid;
62 r=mid-1;
63 }
64 else l=mid+1;
65 }
66 printf("Case %d:",s);
67 printf(" %d\n",answer);
68 }
69 return 0;
70 }
1076 - Get the Containers的更多相关文章
- LightOj 1076 - Get the Containers (折半枚举好题)
题目链接: http://www.lightoj.com/volume_showproblem.php?problem=1076 题目描述: 给出n个数,要求分成m段,问这m段中最大的总和,最小是多少 ...
- lightoj刷题日记
提高自己的实力, 也为了证明, 开始板刷lightoj,每天题量>=1: 题目的类型会在这边说明,具体见分页博客: SUM=54; 1000 Greetings from LightOJ [简单 ...
- Jan's light oj 01--二分搜索篇
碰到的一般题型:1.准确值二分查找,或者三分查找(类似二次函数的模型). 2.与计算几何相结合答案精度要求比较高的二分查找,有时与圆有关系时需要用到反三角函数利用 角度解题. 3.不好直接求解的一类计 ...
- Conquering Keokradong && Get the Containers(二分)
Conquering Keokradong Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu ...
- IBM Bluemix体验:Containers持久存储
上一篇介绍了在Bluemix Containers服务中使用docker hub镜像和container的高可用配置.接下来我们尝试如何在容器中使用持久存储. 在Bluemix的Containers服 ...
- IBM Bluemix体验:Containers进阶
上一篇中介绍了Bluemix的Containers服务以及如何使用自定义的docker image创建一个容器实例并对外提供服务.除了自定义镜像之外,Bluemix Containers还可以使用Do ...
- IBM Bluemix体验:Containers
国际版的Bluemix目前有三个region,US South,United Kingdom和Sydney.其中US South是功能最全的,UK其次,Sydney功能最少.Containers服务在 ...
- Docker-2:network containers
docker run -d -P --name web training/webapp python app.py # -name means give the to-be-run container ...
- Containers Reserved yarn resourcemanager
yarn rm的管理页面中显示了集群的概况,其中有一个指标叫Containers Reserved . 预留的容器,为什么会预留,集群的资源使用饱合,新的app请求的资源一般会进入pending状态, ...
随机推荐
- javaWeb - 3 — JSP (技术已淘汰)— 更新完毕
1.jsp 在servlet中说过java中前端到后台有两条路线嘛 后台 <------ ajax.json <--------- 前端 后台 <------ jsp( EL.JST ...
- 学习java 7.21
学习内容: 模块使用 AWT是窗口框架 它从不同平台的窗口系统中抽取出共同组件,当程序运行时,将这些组件的创建和动作委托给程序所在的运行平台.简而言之,当使用AWT编写图形界面应用时,程序仅指定了界面 ...
- 大厂高频面试题Spring Bean生命周期最详解
Spring作为当前Java最流行.最强大的轻量级框架.Spring Bean的生命周期也是面试高频题,了解Spring Bean周期也能更好地帮助我们解决日常开发中的问题.程序员应该都知道Sprin ...
- day8 基本数据类型之字典
day8 基本数据类型之字典 一.字典(dict) 1.用途: 2.定义方式:在{}内用逗号分隔开多个元素,每个元素都是key:value的形式,其中value可以使任意类型,而key必须是不可变类型 ...
- deque、queue和stack深度探索(上)
deque是可双端扩展的双端队列,蓝色部分就是它的迭代器类,拥有四个指针,第一个cur用来指向当前元素,first指向当前buffer头部,last指向当前buffer尾部,node指向map自己当前 ...
- 100个Shell脚本——【脚本2】截取字符串
[脚本2]截取字符串 一.脚本 现有一个字符串如下: http://www.aaa.com/root/123.htm 请根据以下要求截取出字符串中的字符: 1.取出www.aaa.com/root/1 ...
- 【编程思想】【设计模式】【行为模式Behavioral】策略模式strategy
Python版 转自https://github.com/faif/python-patterns/blob/master/behavioral/strategy.py #!/usr/bin/env ...
- 如何使用gitHub管理自己的项目
GitHub 与 Git Git是一种分布式版本控制系统,与svn是同样的概念 GitHub是一个网站,提供Git服务 前提:你的本机电脑已经安装了git,并且已经注册了gitHub账号 Git上传本 ...
- seata服务端和客户端配置(使用nacos进行注册发现,使用mysql进行数据持久化),以及过程中可能会出现的问题与解决方案
seata服务端和客户端配置(使用nacos进行注册发现,使用mysql进行数据持久化),以及过程中可能会出现的问题与解决方案 说明: 之所以只用nacos进行了注册与发现,因为seata使用naco ...
- Mysql的基操
创建一个数据库 (myschool是数据库名) create database myschool; 删除数据库 drop database myschool 创建一个表:(Student是 表名) ...