HDU 5303 Delicious Apples (2015多校第二场 贪心 + 枚举)
来源:互联网 发布:mac自带终端连接vps 编辑:程序博客网 时间:2024/05/02 11:31
Delicious Apples
Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 321 Accepted Submission(s): 95
Problem Description
There are apple trees planted along a cyclic road, which is metres long. Your storehouse is built at position on that cyclic road.
The th tree is planted at position , clockwise from position . There are delicious apple(s) on the th tree.
You only have a basket which can contain at most 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?
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: , the number of testcases.
Then testcases follow. In each testcase:
First line contains three integers, .
Next lines, each line contains .
Then
First line contains three integers,
Next
Output
Output total distance in a line for each testcase.
Sample Input
210 3 22 28 25 110 4 12 28 25 10 10000
Sample Output
1826
解题思路:
注意到,最多只有一次会绕整个圈走一次,因此,先贪心的处理左半环和右半环,然后枚举绕整圈的时候从左侧摘得苹果和从右侧摘得苹果的数目。
#include <iostream>#include <cstring>#include <cstdio>#include <cstdlib>#include <vector>#include <queue>#include <stack>#include <cmath>#include <algorithm>#define LL long longusing namespace std;const int MAXN = 100000 + 10;int L, N, K;LL x[MAXN];LL ld[MAXN], rd[MAXN];vector<LL>l, r;int main(){ int T; scanf("%d", &T); while(T--) { scanf("%d%d%d", &L, &N, &K); l.clear(); r.clear(); int pos, num, m = 0; for(int i=1;i<=N;i++) { scanf("%d%d", &pos, &num); for(int i=1;i<=num;i++) x[++m] = (LL)pos; } for(int i=1;i<=m;i++) { if(2 * x[i] < L) l.push_back(x[i]); else r.push_back(L - x[i]); } sort(l.begin(), l.end()); sort(r.begin(), r.end()); int lsz = l.size(), rsz = r.size(); memset(ld, 0, sizeof(ld)); memset(rd, 0, sizeof(rd)); for(int i=0;i<lsz;i++) ld[i + 1] = (i + 1 <= K ? l[i] : ld[i + 1 - K] + l[i]); for(int i=0;i<rsz;i++) rd[i + 1] = (i + 1 <= K ? r[i] : rd[i + 1 - K] + r[i]); LL ans = (ld[lsz] + rd[rsz]) * 2; for(int i=0;i<=lsz&&i<=K;i++) { int p1 = lsz - i; int p2 = max(0, rsz-(K-i)); ans = min(ans, 2*(ld[p1] + rd[p2]) + L); } cout << ans << endl; } return 0;}
0 0
- HDU 5303 Delicious Apples (2015多校第二场 贪心 + 枚举)
- 多校第二场 1004 hdu 5303 Delicious Apples(背包+贪心)
- HDU 5303 Delicious Apples (DP) 2015多校联合第二场
- Delicious Apples (hdu 5303 贪心+枚举)
- 2015多校第二场 1004( Delicious Apples )
- HDU 5303 Delicious Apples (贪心 枚举 好题)
- hdu 5303 Delicious Apples 2015多校联合训练赛2 dp+枚举
- HDU 5303 Delicious Apples(贪心 + 背包 2015多校啊)
- hdu 5303 Delicious Apples (DP+枚举)
- HDU 5303 Delicious Apples(DP + 贪心)
- hdu 5303 Delicious Apples(贪心)
- Delicious Apples(贪心+枚举)
- hdu 5303 Delicious Apples
- 【HDU】5303 Delicious Apples
- HDU 5303 Delicious Apples
- hdu5303(2015多校2)--Delicious Apples(贪心+枚举)
- HDU 5303(Delicious Apples- 环上折半dp+贪心)
- HDU 5303 delicious apples(贪心+离散化)好题
- AndroidJNI.SetDoubleArrayElement 设置双精度浮点数数组元素
- SOA的浅析
- 四季歌吉他谱
- hdu 5308 I Wanna Become A 24-Point Master(2015 Multi-University Training Contest 2)
- eclipse中outline中图标含义
- HDU 5303 Delicious Apples (2015多校第二场 贪心 + 枚举)
- log4net配置后不运行,没有日志输出
- ARP概念及攻击与防护的原理(来自中国协议分析网)
- RAID在企业服务器中的应用(RAID几种级别)
- Java String 比较和 Integer 比较
- codeMirror插件使用
- 搭建高可用的MongoDB集群(上):MongoDB的配置与副本集----- 个人记录
- QT中调用JAVA代码
- powerdesigner-去掉name与code的联动