1048-conquering Keokradong
|
PDF (中文版) |
Statistics |
Forum |
Time Limit:1 second (s) |
Memory limit:32 MB |
This winter we is going on a trip to Bandorban. The main target is to climb the top of Keokradong. So, we'll use a trail. The trail is a continuous marked footpath this goes from Bandorban to Keokradong.
Part of the experience are also the route planning of the trip. We have a list of all possible campsites, we can use along the the-and we want to does this-so-we only stopk nights to Camp. We also know in advance the distance between consecutive campsites and we is only allowed to camp at a campsite. Our goal are to plan the trips so, we minimize the maximum amount of walking do in a single day. In other words, if we have trip involves 2 nights (3 days of walking), and we walk 9, ten, 5 miles on each day respectively, th E Cost (maximum amount of walking do in one day) is 10. Another schedule that involves walking 9, 6, and 9 miles on each day have the cost 9.
Given the distances between N consecutive campsites of a trail and Given the number of nights for your trips, K, your task is to devise a camping strategy for the specified trail such that it minimizes the maximum amount of Wal King do in a single day. Note that the first distance value given are the distance from our start-point of the trail to our 1st campsite, and the LA St 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 integers, the number of campsites, N (1≤n≤1000) and the number of nights of the Tri P, K (1≤k≤min (N)). The following N + 1 lines indicate the distance in miles between consecutive campsite locations. All the integers is positive and less than 10000.
Output
For each case of input, you had 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 many solutions, the primary target is to find the one which ensures, which each day we had to walk some dis Tance. For ties, print the one where the distance covered on first day are maximum, then the distance covered in second day is Max Imum 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 Test instructions: Divide the n+1 number into k+1 segments, and find the minimum of the maximum in these segments, and ensure that the smallest case follows the first paragraph with the highest precedence, then the second paragraph .... Idea: two points + greedy first with two points to find the minimum of the maximum is how much, we can know when we divide the number of the smaller then the largest value is greater, so we find, can be divided into the <=k+1 segment of the minimum maximum and then we know the value of the time, the greedy combination before and after, Greedy to select the maximum of each paragraph, and finally as long as the guarantee to take the K+1 segment on the line
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