1048

摘要:
1048征服基奥克拉东PDF(英文)统计数据目标时间限制:1秒内存限制:32MB这个冬天我们要去Bandorban。维护目标是破坏基奥克拉东岛的地形。所以,我们将使用一个地图
1048 - Conquering Keokradong
   PDF (English)StatisticsForum
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
",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
",uu[i]);
88                }
89         }
90         return 0;
91 }
 

免责声明:文章转载自《1048》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇C#获取当前路径一、STM32简介、选型及其目标下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

Foxyproxy 火狐代理插件

Firefox上的插件Autoproxy一直很难使用。它永远不能更新规则,但foxyproxy可以替代它。用鼠标中键单击foxyproxy图标以在不同的代理方法之间切换。foxyproxy图标从foxhead变为蓝色,因为内容传输发生在网页中,该传输通过默认代理服务器,默认代理的初始颜色为蓝色。...

mysql状态查看 QPS/TPS/缓存命中率查看

showglobalstatusslike'Com_ commit';showstatslike“无缓冲池读取%”;Thread_cache_Hits=(1-Thread_created/connections)*100%(8)锁定状态mysql&gt;showstatslike“Binlog_缓存%”;...

001_Three.js中的跨域问题

】当请求的资源和请求脚本不在同一域中时,将发生跨域。有关详细信息,请参见链接。这是一个需要进一步考虑的问题。它是一个装载机。它加载本地资源。为什么要跨域请求?...

Ubuntu安装时怎样分区

应该首先放置启动分区。并将引导设置为主分区。如果是双系统或多系统安装,通常可以选择逻辑分区。首先,Grub可以在1024柱面后面引导Linux内核;第二,即使有多个Linux安装,/boot也可以完全不共享。此外,非独立/引导分区仅占用根文件夹下约20MB的空间。所以决定是否启动。...

mac 安装xcode命令行工具

重印:https://segmentfault.com/a/1190000018045211?utm_source=tag-Newest1.启动终端,输入命令:xcode select--install,然后一直单击install。2.安装成功后,输入命令:gcc-v以检查是否成功。如果在第一步中报告了错误,提示为:xcode select:error:co...

CentOS7上使用history删除部分历史记录

使用history命令删除登录后创建的历史记录,但保留原始记录。如果未执行history命令,则直接使用history-r命令将文件中的历史刷新到此处的缓存中,并且不会保存以前操作的记录。修改后,执行:history-c以清除当前会话历史中的历史缓存-r以读取~/。bash_您可以看到历史文件中的历史记录已在缓存中更新。...