Delicious Apples
Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 395 Accepted Submission(s): 122
Problem Description
Input
First line:
t, the number of testcases.
Then
t testcases follow. In each testcase:
First line contains three integers,
L,n,K.
Next
n lines, each line contains
xi,ai.
Output
Output total distance in a line for each testcase.
Sample Input
2 10 3 2 2 2 8 2 5 1 10 4 1 2 2 8 2 5 1 0 10000
Sample Output
Source
2015 Multi-University Training Contest 2
Recommend
wange2014 | We have carefully selected several similar problems for you: 5309 5308 5307 5306 5305
题意:在一个圆上有n个苹果树,告诉苹果树的位置和每棵树上的苹果个数,还有一个容量为K的篮子,用篮子去摘苹果,起点在位置0,反复去摘直到把所有的苹果都摘回到0,问走的最短距离为多少。
思路:首先将圆一分为二,在圆形两侧能拿满的话肯定就是只走半边再回去,这样比走整圈划算,另外还要想到最后两边都不足K个了,这个时候最多需要走一个整圈,我们不知道这个整圈拿了哪几个苹果,那么就枚举K个。比赛时只是想到了贪心,最后那一部分没有枚举,另外这里的苹果进行了离散化,因为苹果总数只有1e5,大大简化了代码,自己当时写的太冗余=-=
代码:
#include
#include
#include
#include
#include
#include
#include