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 metres
long. Your storehouse is built at position on
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 testcases
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次运算的过程,如果不能输 ...
随机推荐
- UVALIVE 4256 Salesmen
Salesmen Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVALive. Original ...
- ASP.NET-常用正则表达式
常用正则表达式 正则: [RegularExpression(@"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}", ErrorMes ...
- ASP.NET-后台cookie与前台JQUERY解析cookie
在controller中给cookie赋值 HttpCookie cookie =newHttpCookie("pageInfo"); cookie["page_inde ...
- ubuntu下使用Nexus搭建Maven私服
ubuntu下使用Nexus搭建Maven私服 1.私服简介: 私服是架设在局域网的一种特殊的远程仓库,目的是代理远程仓库及部署第三方构件.有了私服之后,当 Maven 需要下载构件时,直接请求私服, ...
- ubuntu中taglist和ctags安装,简单明了
1.使用命令安装ctags: sudo apt-get install ctags 2.安装taglist 下载: http://vim.sourceforge.net/scripts/downloa ...
- 为什么不能用memcached存储Session?
Memcached创建者Dormando非常早就写过两篇文章[1][2].告诫开发者不要用memcached存储Session. 他在第一篇文章中给出的理由大致是说,假设用memcached存储Ses ...
- 火狐访问IIS出现404,而Chrome可以正常访问
需要在web.config中的handlers中添加如下节点,保存之后,需要重启电脑. <remove name="ExtensionlessUrlHandler-Integrated ...
- php中echo什么时候用到\"这个符号
php中echo什么时候用到\"这个符号 当在引号中用到引号时,为避免混乱用\" \称为转义符,表示后面的字符和原来程序语言里的语法符号含义不同 常见的转义有 \" \' ...
- Creating a Custom Page Layout in SharePoint 2013
Creating a Custom Page Layout in SharePoint 2013 In my last article, I documented how to create a Ma ...
- SharePoint 网站中定义的页面背景图片不起作用
If you are working on custom SharePoint 2013 master pages, designs and/or CSS, these little CSS clas ...