Conquering Keokradong && Get the Containers(二分)
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu
Description
This winter we are going on a trip to Bandorban. The main target is to climb up to the top of Keokradong. So, we will use a trail. The trail is a continuous marked footpath that goes from Bandorban to Keokradong.
Part of the experience is also the route planning of the trip. We have a list of all possible campsites that we can use along the way and we want to do this trip so that we only stop K nights to camp. We also know in advance the distance between consecutive campsites and we are only allowed to camp at a campsite. Our goal is to plan the trip so that we minimize the maximum amount of walking done in a single day. In other words, if our trip involves 2 nights (3 days of walking), and we walk 9, 10, 5 miles on each day respectively, the cost (maximum amount of walking done in one day) is 10. Another schedule that involves walking 9, 6, 9 miles on each day has cost 9.
Given the distances between N consecutive campsites of a trail and given the number of nights for your trip, K, your task is to devise a camping strategy for the specified trail such that it minimizes the maximum amount of walking done in a single day. Note that the first distance value given is the distance from our start-point of the trail to our 1st campsite, and the last distance value given is the distance from our Nth campsite to our end-point of the trail.
Input
Input starts with an integer T (≤ 200), denoting the number of test cases.
Each case contains of two integers, the number of campsites, N (1 ≤ N ≤ 1000) and the number of nights of the trip, K (1 ≤ K ≤ min(N, 300)). The following N + 1 lines indicate the distance in miles between consecutive campsite locations. All the integers will be positive and less than 10000.
Output
For each case of input you have to print the case number and the minimized cost as described above. Then print K+1lines, each containing the amount of distance covered in ith day. As there can be many solutions, the primary target is to find the one which ensures that each day we have to walk some distance. For ties, print the one where the distance covered in first day is maximum, then the distance covered in second day is maximum and so on.
Sample Input
1
4 3
7
2
6
4
5
Sample Output
Case 1: 8
7
8
4
5
题解:
就是一个简单的二分,数字通过合并,最小化最大值,输出合并后的情况;写的时候开始wa了,今天看了看,输出的时候出现的问题;例如这组数据
1
4 3
100
2
6
4
5
会出现输出不全;所以要记录下当前输出了多少数字,判断与剩余字的关系就好了;
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int INF = 0x3f3f3f3f;
typedef long long LL;
int num[];
int n, m;
bool js(int x){
int k = , cnt = ;
for(int i = ; i < n; i++){
if(num[i] > x)return false;
k += num[i];
if(k > x){
k = num[i];
cnt++;
}
}
if(cnt <= m)return true;
else return false;
}
int erfen(int l,int r){
int mid, ans = ;
while(l <= r){
mid = (l + r) >> ;
if(js(mid)){
ans = mid;
r = mid - ;
}
else l = mid + ;
}
return ans;
} int main(){
int T, kase = ;
scanf("%d", &T);
while(T--){
scanf("%d%d", &n, &m);
n++;m++;
int temp = , ms = ;
for(int i = ; i < n; i++){
scanf("%d", num + i);
ms = max(ms, num[i]);
temp += num[i];
}
ms = max(ms, erfen(, temp));
printf("Case %d: %d\n", ++kase, ms);
int k = , cnt = ;
for(int i = ; i < n; i++){
if(k + num[i] > ms || n - i < m - cnt){//注意
cnt++;
printf("%d\n", k);
k = num[i];
}
else{
k += num[i];
}
}
printf("%d\n", k);
}
return ;
}
Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu
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:
- 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 jthcontainer, 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<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int INF = 0x3f3f3f3f;
typedef long long LL;
int num[];
int n, m;
bool js(int x){
int k = , cnt = ;
for(int i = ; i < n; i++){
k += num[i];
if(k > x){
k = num[i];
cnt++;
}
}
if(cnt <= m)return true;
else return false;
}
int erfen(int l,int r){
int mid, ans = ;
while(l <= r){
mid = (l + r) >> ;
if(js(mid)){
ans = mid;
r = mid - ;
}
else l = mid + ;
}
return ans;
}
int main(){
int T, kase = ;
scanf("%d", &T);
while(T--){
scanf("%d%d", &n, &m);
int temp = , ms = ;
for(int i = ; i < n; i++){
scanf("%d", num + i);
ms = max(ms, num[i]);
temp += num[i];
}
ms = max(ms, erfen(, temp));
printf("Case %d: %d\n", ++kase, ms);
}
return ; }
Conquering Keokradong && Get the Containers(二分)的更多相关文章
- lightoj.1048.Conquering Keokradong(二分 + 贪心)
Conquering Keokradong Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu ...
- 1048 - Conquering Keokradong
1048 - Conquering Keokradong PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit: ...
- 1076 - Get the Containers
1076 - Get the Containers PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 ...
- BZOJ1012: [JSOI2008]最大数maxnumber [线段树 | 单调栈+二分]
1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec Memory Limit: 162 MBSubmit: 8748 Solved: 3835[Submi ...
- BZOJ 2756: [SCOI2012]奇怪的游戏 [最大流 二分]
2756: [SCOI2012]奇怪的游戏 Time Limit: 40 Sec Memory Limit: 128 MBSubmit: 3352 Solved: 919[Submit][Stat ...
- 整体二分QAQ
POJ 2104 K-th Number 时空隧道 题意: 给出一个序列,每次查询区间第k小 分析: 整体二分入门题? 代码: #include<algorithm> #include&l ...
- 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服务在 ...
随机推荐
- 一个sql很多个not like的简化语句
如: select * from table where `zongbu` not like '%北京%' and `zongbu` not like '%上海%' and `zongbu` not ...
- python threading基础学习
# -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' """ python是支持多线程的,并 ...
- jQuery插件Jeditable的使用(Struts2处理)
Jeditable - Edit In Place Plugin For jQuery,是一款JQuery就地编辑插件.也就是在页面直接点击需要编辑的内容,就会自动变成文本框进行编辑.它的官方 ...
- 5. openCV中常用函数学习
一.前言 经过两个星期的努力,一边学习,一边写代码,初步完成了毕业论文系统的界面和一些基本功能,主要包括:1 数据的读写和显示,及相关的基本操作(放大.缩小和移动):2 样本数据的选择:3 数据归一化 ...
- EffectiveC#17--装箱和拆箱的最小化
1.如下这段代码会经历装箱和拆箱.例如25会先装箱成object后传递给writeline方法(一次拷贝),在方法内部又 经历拆箱成int(第二次拷贝)后然后调用tostring(). Console ...
- Android 控件 -------- AutoCompleteTextView 动态匹配内容,例如 百度搜索提示下拉列表功能
AutoCompleteTextView 支持基本的自动完成功能,适用在各种搜索功能中,并且可以根据自己的需求设置他的默认显示数据.两个控件都可以很灵活的预置匹配的那些数据,并且可以设置输入多少值时开 ...
- Win7刷新环境变量
在“我的电脑”->“属性”->“高级”->“环境变量”中增加或修改环境变量后,需重启系统才能使之生效.有没有什么方法可让它即时生效呢? 下面介绍一种方法: 以修改环境变量“PATH” ...
- 编译错误“The run destination My Mac 64-bit is not valid for Running the scheme '***',解决办法
1. iOS APP Project or Mac APP Project编译错误提示: “The run destination My Mac 64-bit is not valid for Ru ...
- 哪几个数的阶乘末尾有n个零?
题目:哪几个数的阶乘末尾有n个0?其中n是一个正整数,从键盘输入. int main( void ) /* name: zerotail.cpp */ { int num, n, c, m; cout ...
- Js 导出Excel IE ActiveX控件
function ExportExcel() { var oXL = new ActiveXObject("Excel.Application"); //创建excel应用程序对象 ...