2015 Multi-University Training Contest 2 hdu 5303 Delicious Apples
Delicious Apples
Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 1057 Accepted Submission(s): 354
The ith tree is planted at position xi, clockwise from position 0. There are ai delicious apple(s) on the ith tree.
You only have a basket which can contain at most K 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.
Then t testcases follow. In each testcase:
First line contains three integers, L,n,K.
Next n lines, each line contains xi,ai.

int a = Lsize - i; 表示的是什么呢?表示从左半圆选择i个 那么剩下的部分不跨圆,继续使用拿完原路返回策略
int b = max(0,Rsize - (K - i)); 剩下的 K- i个采用拿了原路返回的策略
ret = min(ret,((sum[a][0] + sum[b][1])<<1) + Len); 那么这K个,我们采用拿了 不原路返回,采用绕圆的方法
所以多了Len
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = ;
LL d[maxn],tot,sum[maxn][];
vector<LL>L,R;
int main() {
int kase,n,K,m,pos;
LL Len;
scanf("%d",&kase);
while(kase--) {
scanf("%d%d%d",&pos,&n,&K);
L.clear();
R.clear();
Len = pos;
for(int i = tot = ; i < n; ++i) {
scanf("%d%d",&pos,&m);
for(int j = ; j < m; ++j)
d[tot++] = pos;
}
for(int i = ; i < tot; ++i) {
if(d[i]* < Len) L.push_back(d[i]);
else R.push_back(Len - d[i]);
}
sort(L.begin(),L.end());
sort(R.begin(),R.end());
int Lsize = L.size(),Rsize = R.size();
sum[][] = sum[][] = ;
for(int i = ; i < Lsize; ++i)
if(i + <= K) sum[i + ][] = L[i];
else sum[i + ][] = sum[i - K + ][] + L[i];
for(int i = ; i < Rsize; ++i)
if(i + <= K) sum[i+][] = R[i];
else sum[i+][] = sum[i-K+][] + R[i];
LL ret = (sum[Lsize][] + sum[Rsize][])<<;
for(int i = ; i <= Lsize && i <= K; ++i) {
int a = Lsize - i;
int b = max(,Rsize - (K - i));
ret = min(ret,((sum[a][] + sum[b][])<<) + Len);
}
cout<<ret<<endl;
}
return ;
}
2015 Multi-University Training Contest 2 hdu 5303 Delicious Apples的更多相关文章
- HDU 5303 Delicious Apples(贪心 + 背包 2015多校啊)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5303 Problem Description There are n apple trees plan ...
- HDU 5303 Delicious Apples (贪心 枚举 好题)
Delicious Apples Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Other ...
- HDU 5303 Delicious Apples(思维题)
Delicious Apples Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Other ...
- [多校2015.02.1004 dp] hdu 5303 Delicious Apples
题意: 在一个长度为L的环上有N棵苹果树.你的篮子容量是K个苹果. 每棵苹果树上都有a[i]个苹果. 问你从0点出发最少要走多少距离能拿完所有的苹果. 思路: 我们考虑dp,dp[0][i]代表顺时针 ...
- HDU 5303 Delicious Apples (2015多校第二场 贪心 + 枚举)
Delicious Apples Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Other ...
- HDU 5303 Delicious Apples 美味苹果 (DP)
题意: 给一个长为L的环,起点在12点钟位置,其他位置上有一些苹果,每次带着一个能装k个苹果的篮子从起点出发去摘苹果,要将全部苹果运到起点需要走多少米? 思路: 无论哪处地方,只要苹果数超过k个,那么 ...
- hdu 5303 Delicious Apples
这道题贪心 背包 假设在走半圆之内能够装满,那么一定优于绕一圈回到起点.所以我们从中点将这个分开,那么对于每一个区间由于苹果数非常少,所以能够利用pos[x]数组记录每一个苹果所在的苹果树位置,然后将 ...
- 多校第二场 1004 hdu 5303 Delicious Apples(背包+贪心)
题目链接: 点击打开链接 题目大意: 在一个周长为L的环上.给出n棵苹果树.苹果树的位置是xi,苹果树是ai,苹果商店在0位置,人的篮子最大容量为k,问最少做多远的距离可以把苹果都运到店里 题目分析: ...
- 2015 Multi-University Training Contest 8 hdu 5390 tree
tree Time Limit: 8000ms Memory Limit: 262144KB This problem will be judged on HDU. Original ID: 5390 ...
随机推荐
- NuSOAP笔记:如何创建复杂数据类型
PHP已经有了内置的SOAP扩展,但是它不具备自动生成WSDL的能力,所以很多时候,NuSOAP还是有一定诱惑力的. 在应用稍微复杂点的时候,单靠integer, string等简单数据类型是不能满足 ...
- CF508E (贪心+搜索+构造)
题目大意:让你构造一个括号序列,括号匹配的方式类似于栈,给出从左数每个括号 到和它匹配的右括号的 最小和最大距离,让你输出一个合法括号序列 看错题了以为是二分图,然后写了搜索 贪心发现如果距离往小了填 ...
- Python多环境扩展管理
Python发展至今,版本众多,在使用过程中经常遇到第三方库依赖的Python版本和系统Python版本不一致的情况.同时又因系统底层需调用当前版本Python,所以不能随意变更当前系统Python版 ...
- web前端开发技术栈分析图
- web.xml中Filter过滤器标签说明
原文:http://www.cnblogs.com/edwardlauxh/archive/2010/03/11/1918618.html 在研究liferay框架中看到Web.xml中加入了过滤器的 ...
- 使用hbase遇到的问题
1.在使用hbase的时候 有很多问题,其中一个 使用sqoop import 从mysql 向hbase导入数据,报错:Error: java.lang.RuntimeException: Coul ...
- POJ 3696
这里面的一个转换的小技巧很重要,把888...8转换成(10^x-1)/9*8.神来之笔,佩服. 这样有(10^x-1)/9*8=L*p得10^x-1=L*p*9/8,设m=9*L/gcd(L,8). ...
- Android中的单位
Android中的单位 1.px 像素(pixels) VGA 480*640像素 (Video Graphics Array) QVGA 240*320像素 (Quarter VGA) HVGA 3 ...
- bzoj4547: Hdu5171 小奇的集合(矩阵乘法)
4547: Hdu5171 小奇的集合 题目:传送门 题解: 做一波大佬们的坑...ORZ 不得不说,我觉得矩阵很简单啊,就一个3*3的(直接看代码吧) 给个递推柿纸:f[i]=f[i-1]+max1 ...
- php设计模式之责任链模式
php设计模式之责任链模式 实际问题 你的论坛有举报功能,版主能解决粗口方面的举报,警察能解决严重一点的黄赌毒方面的举报,更严重的反政府的举报就需要由国安局来完成. 职场中每个人都有直属的上级,如果到 ...