Light oj 1048Conquering Keokradong
来源:互联网 发布:历年人口普查数据 编辑:程序博客网 时间:2024/06/05 01:53
J - Conquering Keokradong
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu
Submit
Status
Practice
LightOJ 1048
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+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
1
4 3
7
2
6
4
5
Sample Output
Case 1: 8
7
8
4
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu
Submit
Status
Practice
LightOJ 1048
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+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
1
4 3
7
2
6
4
5
Sample Output
Case 1: 8
7
8
4
5
和上一个一样,,,二分比较,多一次输出,,,,一定要输出m+1组和。。。
代码:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int n,m,shu[1050];int zhao(int xx){bool fafe=true;int s=0,ge=1;for (int i=1;i<=n;i++){if (s+shu[i]>xx){ge++;s=shu[i];}elses+=shu[i];}if (ge<=m) return true;else return false;}void zh(int xx){int s=0,ge=1;bool fafe=false;int p=m;for (int i=1;i<=n;i++){if (fafe){printf("%d\n",shu[i]);continue;}if (s+shu[i]<=xx&&n-i==p-1){s+=shu[i];//printf("%d %d 666\n",i,s);printf("%d\n",s);fafe=true;continue;}else if (s+shu[i]>xx){ge++;printf("%d\n",s);p--;s=shu[i];}elses+=shu[i];}if (!fafe)printf("%d\n",s);}int main(){int t;scanf("%d",&t);for (int ca=1;ca<=t;ca++){scanf("%d%d",&n,&m);n++;m++;int le=0,mid,ri=0,ans;for (int i=1;i<=n;i++){scanf("%d",&shu[i]);le=max(le,shu[i]);ri+=shu[i];}while (ri>=le){mid=(ri+le)/2;if (zhao(mid)){ans=mid;ri=mid-1;}else{le=mid+1;}}printf("Case %d: %d\n",ca,ans);zh(ans);}return 0;}
0 0
- Light oj 1048Conquering Keokradong
- 【Light】[1048]Conquering Keokradong
- Conquering Keokradong LightOJ 1048
- LightOJ 1048 Conquering Keokradong | 二分
- LightOJ 1048 - Conquering Keokradong 【二分】
- LightOJ 1048 Conquering Keokradong (二分)
- LightOJ - 1048 Conquering Keokradong(贪心)
- LightOJ 1048 - Conquering Keokradong(二分)
- lightoj 1048 - Conquering Keokradong 二分答案
- lightoj 1048 - Conquering Keokradong 【二分 + 贪心】
- LightOJ 1048 - Conquering Keokradong(二分逼近)
- LightOJ 1048 Conquering Keokradong(二分+贪心)
- lightoj1048 Conquering Keokradong
- LightOJ - 1048 Conquering Keokradong (二分)输出路径
- light oj
- light oj
- Light OJ
- Light OJ
- 大学生活之我见
- 11gR2 集群管理软件(GI) 启动顺序和诊断方法简介
- LaTeX----$$中的字母如何由斜体变成正体
- Matlab----网络爬虫例子
- 第八周上机实践项目——项目4-游戏中的角色类增强版-问题(2)
- Light oj 1048Conquering Keokradong
- 感言
- h5入门篇之标签元素
- 选择问题(第k小元素)(分治法)
- 第4章 C语言及程序设计提高例程-21 首尝排序——冒个泡
- 韓長庚先生 (迹)
- HTML5 获取用户经纬度及距离计算公式
- Thrift的安装和简单示例
- 一丝领悟------------------------------------未泯的童心