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服务在 ...
随机推荐
- Spring Tool Suit 在Eclipse上的安装
登录http://spring.io/tools/sts/all 下载所需的Spring Tool Suit安装包 我用的是springsource-tool-suite-3.6.1.RELEASE- ...
- Staple: Complementary Learners For Real-time Tracking Tracking
转载注明出处: http://www.cnblogs.com/sysuzyq/p/6169414.html By 少侠阿朱 讨论班上的PPT 1.同学大家好.今天给大家讲一篇单目标跟踪的论文,方法比较 ...
- 制作nginx的rpm包出现问题
在学习打包rpm,找到了个不错的参考站点 https://src.fedoraproject.org/cgit/rpms/ 过程: git clone -b el6 git://pkgs.fedor ...
- Microsoft Visual C++ 不支持long long
Microsoft Visual C++ 不支持long long 在C/C++中,64为整型一直是一种没有确定规范的数据类型.现今主流的编译器中,对64为整型的支持也是标准不一,形态各异.一般来说, ...
- jquery 根据网站url给导航nav添加active效果
后台的同事因为把nav公用了,所以无法单页添加active,一下方法通过判断url的后缀给当前页添加active $(function(){ var _nava= $('.nav .nav-wrapp ...
- DOM生成&解析
开篇注意,由于解析有可能有大文件非常耗时,建议另开一个线程解析也可以不开具体视情况而定 DOM生成 1.拿到Document的工厂实例化 DocumentBuilderFactory df = ...
- 创建一个简单的配置android编译环境的脚本
由于有多个Android项目,每个项目配置编译环境时选项都不同,所以尝试写一个sh脚本来完成这个功能. 首先进入bin文件夹,新建一个文件enbuild $ cd ~/bin $ touch ...
- ios 异步多线程 获取数据
简介 iOS有三种多线程编程的技术,分别是: (一)NSThread (二)Cocoa NSOperation (三)GCD(全称:Grand Central Dispatch) 这三种编程方式 ...
- Linux命令查询手册--sort
一.sort的工作原理 sort将文件的每一行作为一个单位,相互比较,比较原则是从首字符向后,依次按ASCII码值进行比较,最后将他们按升序输出. 二.sort的参数选项 1. sort -u 在输出 ...
- zongjie
$msg = $_GET['msg'];$startDate = $_POST['startDate'];$endDate = $_POST['endDate'];$quickdate = $_POS ...