1048 - Conquering Keokradong
Time Limit: 1 second(s) Memory Limit: 32 MB

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+1 lines, 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

Output for Sample Input

1

4 3

7

2

6

4

5

Case 1: 8

7

8

4

5


PROBLEM SETTER: JANE ALAM JAN
题意:将N+1个数分成K+1段,并且求这些段中的最大值的最小是多少,并且保证最小的情况下按照第一段最大优先,然后第二段。。。。
思路:二分+贪心
先用二分去找最大值的最小是多少,我们可以知道当我们分的段数越小那么这个最大的值就越大,所以我们二分找到,可以分成<=k+1段的最小的最大值
然后我们知道这个值的时候,贪心组合按前到后,贪心选到每段的最大,最后只要保证取到K+1段就行
 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+1);
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 check(answer,n,m);
69 int ac=0; sum=0;
70 int cnt=1;
71 for(i=0;i<=n;i++)
72 {
73 if(sum+ans[i]>answer||(n-i-1)<m-cnt)
74 {
75 uu[cnt-1]=sum;
76 sum=ans[i];
77 cnt++;
78 }
79 else
80 {
81 sum+=ans[i];
82 }
83 }
84 uu[cnt-1]=sum;
85 for(i=0;i<m+1;i++)
86 {
87 printf("%d\n",uu[i]);
88 }
89 }
90 return 0;
91 }
 

1048 - Conquering Keokradong的更多相关文章

  1. lightoj.1048.Conquering Keokradong(二分 + 贪心)

    Conquering Keokradong Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu ...

  2. Conquering Keokradong && Get the Containers(二分)

    Conquering Keokradong Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu ...

  3. NYOJ题目1048破门锁

  4. hdu 4848 Wow! Such Conquering! (floyd dfs)

    Wow! Such Conquering! Problem Description There are n Doge Planets in the Doge Space. The conqueror ...

  5. AC日记——石子归并 codevs 1048

    1048 石子归并  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解  查看运行结果     题目描述 Description 有n堆石子排成一列,每堆石子 ...

  6. 【BZOJ】1048: [HAOI2007]分割矩阵

    http://www.lydsy.com/JudgeOnline/problem.php?id=1048 题意:给出一个a×b(a,b<=10)的矩阵,带一个<=100的权值,现在要切割n ...

  7. PAT 解题报告 1048. Find Coins (25)

    1048. Find Coins (25) Eva loves to collect coins from all over the universe, including some other pl ...

  8. 【BZOJ】【1048】【HAOI2007】分割矩阵

    DP/记忆化搜索 暴力枚举分割方案?……大概是指数级的?大约是20!的方案= =? 但是我们看到a.b.n的范围都很小……所以不同的状态数只是$10^5$级别的,可以记忆化搜索求解 比较水的一道题…… ...

  9. PAT-乙级-1048. 数字加密(20)

    1048. 数字加密(20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 本题要求实现一种数字加密方法.首先固 ...

随机推荐

  1. 云原生时代的 APM

    作者 | 刘浩杨 来源|尔达 Erda 公众号 ​APM 的全称是 Application Performance Management(应用性能管理),早在 90 年代中期就有厂商提出性能管理的概念 ...

  2. 8. LINUX shell 环境变量

    wc –l file 计算文件行数, wc -w file  计算文件中的单词数, wc -c file   计算文件中的字符数 查看文件内容: cat .more

  3. 寻找pair

    给定n个整数使其两两组合成一对pair,例如给定 1 ,2 可以组成的pair为(1,1),(1,2),(2,1),(2,2),然后在这些pair中寻找第k小的pair. 输入第一行包含两个数字,第一 ...

  4. 在调用系统相册时,UIIMagePickerController使用中偷换StatusBar颜色的问题

    在调用系统相册时,UIIMagePickerController使用中偷换StatusBar颜色的问题 此时解决办法是 #pragma mark - UIImagePickerController D ...

  5. transient关键字和volatile关键字

    看到HashSet的源代码的时候,有一个关键字不太认识它..transient,百度整理之: Java的Serialization提供了一种持久化对象实例的机制,当持久化对象时,可能有一些特殊的对象数 ...

  6. 测试JDBCUtils的重用性

    package cn.itcast.jdbc;import cn.itcast.util.JDBCUtils;import java.sql.*;import java.util.Properties ...

  7. [云原生]Docker - 容器

    目录 Docker容器 启动容器 新建并启动 启动已终止容器 守护态运行容器 终止容器 进入容器 attach命令 exec命令 导出和导入容器 导出容器 导入容器 删除容器 Docker容器 容器是 ...

  8. C#中继承和多态

    1.继承的概念 继承是使用已存在的类的定义作为基础建立新类的技术,新类的定义可以增加新的数据或新的功能,也可以用已存在的类的功能. 为了提高软件模块的可复用性和可扩充性,以便提高软件的开发效率,我们总 ...

  9. gitlab的分支保护配置

    目录 一.简介 二.Gitlab配置步骤 一.简介 开发当前开发的分支遇到暂时无法解决的问题,现在有需要开发其他应用,所以希望运维这边将当前有问题分支冻结,让其他人无法进行修改,待后续有时间在排查代码 ...

  10. pipeline 结构设计

    目录 一.pipeline步骤 二.案例 pipeline详解 只生成一次制品 不同环境部署 系统集成测试 指定版本部署 一.pipeline步骤 当团队开始设计第一个pipeline时,该如何下手呢 ...