LightOJ - 1048 Conquering Keokradong (二分)输出路径
来源:互联网 发布:接入网的用户网络接口 编辑:程序博客网 时间:2024/06/01 13:16
Submit Status
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
Source
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespace std;const int INF = 0x3f3f3f3f;typedef long long LL;int num[1010];int n, m;bool js(int x){int k = 0, cnt = 1;for(int i = 0; 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 = 0;while(l <= r){mid = (l + r) >> 1;if(js(mid)){ans = mid;r = mid - 1;}else l = mid + 1;}return ans;}int main(){int T, kase = 0;scanf("%d", &T);while(T--){scanf("%d%d", &n, &m);n++;m++;int temp = 0, ms = 0;for(int i = 0; i < n; i++){scanf("%d", num + i);ms = max(ms, num[i]);temp += num[i];}ms = max(ms, erfen(1, temp));printf("Case %d: %d\n", ++kase, ms);int k = 0, cnt = 0;for(int i = 0; i < n; i++){if(k + num[i] > ms || n - i < m - cnt){cnt++;printf("%d\n", k);k = num[i];}elsek += num[i];}printf("%d\n", k);}return 0;}
- 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(二分+贪心)
- Conquering Keokradong LightOJ 1048
- LightOJ - 1048 Conquering Keokradong(贪心)
- 【Light】[1048]Conquering Keokradong
- Light oj 1048Conquering Keokradong
- lightoj1048 Conquering Keokradong
- loj1048Conquering Keokradong 二分
- lightoj 1110 - An Easy LCS (LCS输出路径)
- lightoj 1138 (二分)
- HDU 2819 Swap (最大二分匹配+输出路径)
- 南京理工大学第八届程序设计大赛-琪露诺的算术教室
- HDU 1571 下沙小面的(1)
- AnkhSvn教程
- Kendo Grid MVC Hierarchy with Aggregate
- mac 下 sublime 如何直接运行 javascript
- LightOJ - 1048 Conquering Keokradong (二分)输出路径
- Android Camera学习(一):如何实现转动屏幕界面菜单跟着转动效果
- idea热加载
- springboot servlet最佳例子
- pigpio-12c-python 学习笔记
- 2013 - Lost connection to MySQL server at ‘reading initial communication packet’, system error: 0
- tableView隐藏多余的分割线Extra cells separator
- maven项目站点生成
- js 设置 读取cookie