HDU 5303 Delicious Apples (2015多校第二场 贪心 + 枚举)
Delicious Apples
Time Limit: 5000/3000 MS (Java/Others) Memory
Limit: 524288/524288 K (Java/Others)
Total Submission(s): 321 Accepted Submission(s): 95
appletrees planted along a cyclic road, which is
metreslong. Your storehouse is built at position
onthat cyclic road.
The
rev=2.4-beta-2" alt="" style="">th
tree is planted at position
rev=2.4-beta-2" alt="" style="">
,
clockwise from position
.
There are
rev=2.4-beta-2" alt="" style="">
delicious
apple(s) on the
rev=2.4-beta-2" alt="" style="">th
tree.
You only have a basket which can contain at most
rev=2.4-beta-2" alt="" style=""> 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?

rev=2.4-beta-2" alt="" style="">

rev=2.4-beta-2" alt="" style="">
rev=2.4-beta-2" alt="" style="">



rev=2.4-beta-2" alt="" style="">
rev=2.4-beta-2" alt="" style="">







rev=2.4-beta-2" alt="" style="">





rev=2.4-beta-2" alt="" style="">



rev=2.4-beta-2" alt="" style="">
rev=2.4-beta-2" alt="" style="">

rev=2.4-beta-2" alt="" style="">
rev=2.4-beta-2" alt="" style="">

rev=2.4-beta-2" alt="" style="">
rev=2.4-beta-2" alt="" style="">
There are less than 20 huge testcases, and less than 500 small testcases.
,the number of testcases.
Then
testcasesfollow. In each testcase:
First line contains three integers,
rev=2.4-beta-2" alt="" style="">
rev=2.4-beta-2" alt="" style="">
.
Next
rev=2.4-beta-2" alt="" style=""> lines,
each line contains 
rev=2.4-beta-2" alt="" style="">

rev=2.4-beta-2" alt="" style="">.
2
10 3 2
2 2
8 2
5 1
10 4 1
2 2
8 2
5 1
0 10000
18
26
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#define LL long long
using 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;
}
HDU 5303 Delicious Apples (2015多校第二场 贪心 + 枚举)的更多相关文章
- hdu 5305 Friends(2015多校第二场第6题)记忆化搜索
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5305 题意:给你n个人,m条关系,关系可以是online也可以是offline,让你求在保证所有人on ...
- HDU 5301 Buildings(2015多校第二场)
Buildings Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Tota ...
- 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/Other ...
- 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 ...
- HDU 5303 Delicious Apples(贪心 + 背包 2015多校啊)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5303 Problem Description There are n apple trees plan ...
- [多校2015.02.1004 dp] hdu 5303 Delicious Apples
题意: 在一个长度为L的环上有N棵苹果树.你的篮子容量是K个苹果. 每棵苹果树上都有a[i]个苹果. 问你从0点出发最少要走多少距离能拿完所有的苹果. 思路: 我们考虑dp,dp[0][i]代表顺时针 ...
- 多校第二场 1004 hdu 5303 Delicious Apples(背包+贪心)
题目链接: 点击打开链接 题目大意: 在一个周长为L的环上.给出n棵苹果树.苹果树的位置是xi,苹果树是ai,苹果商店在0位置,人的篮子最大容量为k,问最少做多远的距离可以把苹果都运到店里 题目分析: ...
- hdu 5308 (2015多校第二场第9题)脑洞模拟题,无语
题目链接:http://acm.hdu.edu.cn/listproblem.php?vol=44 题意:给你n个n,如果能在n-1次运算之后(加减乘除)结果为24的输出n-1次运算的过程,如果不能输 ...
随机推荐
- 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 ...
- 洛谷 P2393 yyy loves Maths II
P2393 yyy loves Maths II 题目背景 上次蒟蒻redbag可把yyy气坏了,yyy说他只是小学生,蒟蒻redbag这次不坑他了. 题目描述 redbag给了yyy很多个数,要yy ...
- Java7的那些新特性
本文介绍的java 7新特性很多其它的感觉像是语法糖.毕竟java本身已经比較完好了.不完好的非常多比較难实现或者是依赖于某些底层(比如操作系统)的功能. 不过java7也实现了类似aio的强大功能. ...
- centos下mysql多实例安装3306、3307实例(2014-10-15)
背景说明 mysql的安装方法有多种,如二进制安装.源代码编译安装.yum安装等.yum安装仅仅能安装mysql 5.1 版本号:源代码安装编译的过程比較长.若没有对源代码进行改动且要求使 ...
- Baby_Step,Gaint_Step(分析具体解释+模板)
下面是总结自他人博客资料.以及本人自己的学习经验. [Baby_Step,Gaint_Step定义] 高次同余方程. BL == N (mod P) 求解最小的L.因为数据范围非常大,暴力不行 这里用 ...
- 【跟我一步一步学Struts2】——拦截器
前言 前面提到过拦截器.而且说拦截器仅仅能拦截Action.这里拦截器的调用体现了责任链模式.为什么说体现了责任链模式呢? 以下的一段话说的非常明确: Struts2将整个运行划分成若干同样类型的元素 ...
- MongoDB增加数据
MongoDB中出了增加之外,其他的操作都很麻烦. 例子: 1.简单的 db.infos.insert({"url":"www.baidu.com"}); 2. ...
- apiCloud中openFrameGroup传参
apiCloud中openFrameGroup传参 1.无效的 api.openFrameGroup({ // 打开 frame 组 name: 'group', scrollEnabled: fal ...
- [JZOJ 5893] [NOIP2018模拟10.4] 括号序列 解题报告 (Hash+栈+map)
题目链接: https://jzoj.net/senior/#main/show/5893 题目: 题解: 考虑暴力怎么做,我们枚举左端点,维护一个栈,依次加入元素,与栈顶元素和栈内第二个元素相同时弹 ...
- [转]m3u8直播测试地址
http://www.cnblogs.com/yuandaozhe/p/5755453.html 调试m3u8的时候需要测试地址 找了几个,备用一下 安徽卫视 http://stream2.ahtv. ...