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

trees planted along a cyclic road, which is

long. Your storehouse is built at position

that 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

follow. 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次运算的过程,如果不能输 ...
随机推荐
- CSS解决ul下面最后一个li的margin
1.运用css3的nth-child(3n): <!DOCTYPE html> <html> <head> <meta charset="UTF-8 ...
- Java基础学习总结(56)——学java必知十大学习目标
诞生至今已有20年的Java,现在依然有很多人使用.回顾过去十五年的成果,Java一直是数一数二的.Java已经成为世界范围内应用最为广泛的编程语言之一.那么在学java的时候你知道到底要学什么吗?一 ...
- RabbitMQ学习总结(3)——入门实例教程详解
一.起航 本章节,柯南君将从几个层面,用官网例子讲解一下RabbitMQ的实操经典程序案例,让大家重新回到经典"Hello world!"(The simplest thing t ...
- 在IDEA中代码自动提示第一个字母大小写必须匹配的解决
在IDEA中代码自动提示第一个字母大小写必须匹配的解决 学习了:http://blog.csdn.net/babys/article/details/41775715 setting>Edito ...
- Hibernate的多种关系映射(oto、otm、mtm)
前提:使用注解映射 一.一对一(夫妻关系表) 两个表:hus1和wife1表,外键为id,各自有名字hname和wname 映射得到两个类:Hus1和Wife1类 Hus1类(主表): package ...
- HDU 1051: Wooden Sticks(贪心)
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- Kettle的四大不同环境工具
不多说,直接上干货! kettle里有不同工具,分别用于ETL的不同阶段. 初学者,建议送Spoon开始.高手,是四大工具都会用. Sqoop: 图形界面工具,快速设计和维护复杂的ETL工作流.集成开 ...
- Enable .Net 4.5 in IIS on Windows 8.1
Setting up a new development box for myself I had forgotten all about the necessity to use theaspnet ...
- SQL SERVER 提取字符串中汉字
IF OBJECT_ID('DBO.GET_ZNSTR') IS NOT NULLDROP FUNCTION DBO.GET_ZNSTRGOCREATE FUNCTION DBO.GET_ZNSTR( ...
- MariaDB GALERA 集群双节点部署
节点1:10.2.2.41 节点2:10.2.2.42 软件: mariadb-galera-10.0.22-linux-x86_64.tar.gz #galera相关参数:(两个节点配置文件类似) ...