hdu5303 Delicious Apples
来源:互联网 发布:爱知时计科技有限公司 编辑:程序博客网 时间:2024/05/17 09:06
Delicious Apples
Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 436 Accepted Submission(s): 133
Problem Description
There are n apple trees planted along a cyclic road, which is L metres long. Your storehouse is built at position 0 on that cyclic road.
Thei th tree is planted at position xi , clockwise from position 0 . There are ai delicious apple(s) on the i th tree.
You only have a basket which can contain at mostK apple(s). You are to start from your storehouse, pick all the apples and carry them back to your storehouse using your basket. What is your minimum distance travelled?
1≤n,k≤105,ai≥1,a1+a2+...+an≤105
1≤L≤109
0≤x[i]≤L
There are less than 20 huge testcases, and less than 500 small testcases.
The
You only have a basket which can contain at most
There are less than 20 huge testcases, and less than 500 small testcases.
Input
First line: t , the number of testcases.
Thent testcases follow. In each testcase:
First line contains three integers,L,n,K .
Nextn lines, each line contains xi,ai .
Then
First line contains three integers,
Next
Output
Output total distance in a line for each testcase.
#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;long long dp[100001],dp1[100001],a[100001];int main(){int T,n,k,x,y;long long l;scanf("%d",&T);while(T--){scanf("%I64d%d%d",&l,&n,&k);int m=0;for(int i=0;i<n;i++){scanf("%d%d",&x,&y);while(y){y--,m++;a[m]=x;}}sort(a+1,a+m+1);dp[0]=0;dp1[m+1]=0;for(int i=1;i<=m;i++)if(i-k<0) dp[i]=min(a[i]*2,l);else dp[i]=dp[i-k]+min(a[i]*2,l);for(int i=m;i>0;i--)if(i+k>m) dp1[i]=min((l-a[i])*2,l);else dp1[i]=dp1[i+k]+min((l-a[i])*2,l);long long ans=dp[0]+dp1[1];for(int i=1;i<=m;i++)ans=min(ans,dp[i]+dp1[i+1]);printf("%I64d\n",ans);}}
0 0
- hdu5303 Delicious Apples
- Hdu5303 Delicious Apples 贪心
- hdu5303 Delicious Apples
- HDU5303 Delicious Apples(贪心)
- HDU5303 Delicious Apples【贪心】【DP】
- 解题报告 之 HDU5303 Delicious Apples
- hdu5303(2015多校2)--Delicious Apples(贪心+枚举)
- 2015 Multi-University Training Contest 2 1004 Delicious Apples(HDU5303)
- hdu 5303 Delicious Apples
- 【HDU】5303 Delicious Apples
- HDU 5303 Delicious Apples
- HDU 5303 Delicious Apples(dp)
- hdu 5303 Delicious Apples(dp)
- Delicious Apples(贪心+枚举)
- Delicious Apples (hdu 5303 贪心+枚举)
- HDU 5303 Delicious Apples(思维题)
- Delicious Apples(多校联合训练)
- HDOJ 5303 Delicious Apples 枚举+DP
- Linux如何查看硬件信息
- 网站对$ua->agent("Mozilla/8.0")的校验
- MP4文件点播seek原理
- 依赖注入——让iOS代码更简洁
- 数字字符、数组处理
- hdu5303 Delicious Apples
- Oracle存在修改,不存在插入记录
- 感知机(perceptron)学习算法的原始形式
- Algorithms—24.Swap Nodes in Pairs
- Linux 文件系统的目录结构
- String,StringBuilder和StringBuffer区别及使用场景
- KMP算法(部分重要代码)
- caffe for windows 训练cifar10
- 1002 A + B Problem II