AGC027 B - Garbage Collector 枚举/贪心
目录
题目链接
题解
对于一组选取组的最优方案为,走到一点,然后顺着路径往回取点
设选取点坐标升序为{a,b,c,d}
那么消耗为\(d+(d - c) + 4* (d - c) + 9 * (c - d) + 16 * (b - a) + a * 25\)
化简后为\(5d + 5c + 7b - 9a\),那个对于这组k的最优解显然是让最远的点系数最小
考虑把序列划分为n / k组,枚举这个k计算,那么复杂度是调和级数的
代码
#include<cstdio>
#include<cstring>
#include<algorithm>
#define gc getchar()
#define pc putchar
#define int long long
inline int read() {
int x = 0,f = 1;
char c = gc;
while(c < '0' || c > '9') {if(c == '-')f = -1; char c = getchar();}
while(c <= '9' && c >= '0') x = x * 10 + c - '0',c = getchar();
return x * f;
}
void print(long long x) {
if(x < 0) {
pc('-');
x = -x;
}
if(x >= 10) print(x / 10);
pc(x % 10 + '0');
}
const int maxn = 500007;
#define LL long long
LL ans;
LL sum[maxn],a[maxn];
main() {
LL n = read(), x = read();
for(int i = 1;i <= n;++ i) a[i] = read(),sum[i] = sum[i - 1] + a[i],ans += 1ll * 5 * a[i] + 2ll * x;
for(int k = 1;k < n;++ k) {
LL tmp = k * x;
for(int nxj,j = n,cnt = 1;j > 0;j = nxj,cnt ++) {
nxj = std::max(j - k,0ll);
LL s = sum[j] - sum[nxj];
tmp += std::max(5ll,cnt * 2ll + 1ll) * s;
if(tmp > ans) break;
}
ans = std::min(ans,tmp);
}
print(ans + 1ll * n * x); pc('\n');
return 0;
}
AGC027 B - Garbage Collector 枚举/贪心的更多相关文章
- 2018.09.16 atcoder Garbage Collector(贪心)
传送门 昨晚打比赛的时候不是很机智啊. 这道题贪心就能过了. 我们可以发现一个明显的结论,每次选的垃圾的距离从大到小排序之后,每个距离对答案的贡献的系数是5,5,7,9,11-也就是最远的是5,其余都 ...
- agc 027 B - Garbage Collector
B - Garbage Collector https://agc027.contest.atcoder.jp/tasks/agc027_b 题意: x坐标轴上n个垃圾,有一个机器人在从原点,要清扫垃 ...
- [GC]一个简单的Garbage Collector的实现
前言: 最近看了google的工程师写的一个非常简单的垃圾收集器,大概200多行C代码,感叹大牛总能够把复杂的东西通过很简单的语言和代码表达出来.为了增加自己的理解,决定把大牛的想法和代码分析一遍,与 ...
- 一个简单的Garbage Collector的实现
一个简单的Garbage Collector的实现 前言: 最近看了google的工程师写的一个非常简单的垃圾收集器,大概200多行C代码,感叹大牛总能够把复杂的东西通过很简单的语言和代码表达出来.为 ...
- D. Diverse Garland Codeforces Round #535 (Div. 3) 暴力枚举+贪心
D. Diverse Garland time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- New Garbage Collector http://wiki.luajit.org/New-Garbage-Collector
New Garbage Collector http://wiki.luajit.org/New-Garbage-Collector GC Algorithms This is a short ove ...
- c++ [wrong]simple "Garbage Collector"
In fact, Ptr alone can accomplish the task mentioned below. Implementation see Ptr.h, main2.cpp. In ...
- Getting Started with the G1 Garbage Collector(译)
原文链接:Getting Started with the G1 Garbage Collector 概述 目的 这篇教程包含了G1垃圾收集器使用和它如何与HotSpot JVM配合使用的基本知识.你 ...
- 51nod1625(枚举&贪心)
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1625 题意:中文题诶- 思路:枚举+贪心 一开始写的行和列同时 ...
随机推荐
- 之手算KD-tree
转自:https://zhuanlan.zhihu.com/p/27453420 本文来源于Machine Learning: Clustering & Retrieval | Courser ...
- SpringBoot定制错误的Json数据
(1)自定义异常处理&返回定制Json数据 @ControllerAdvice public class MyExceptionHandler { @ResponseBody @Excepti ...
- 使用Eclipse创建Web Services
正文: 项目源文件: 百度云盘/博客园/project/wsServerExample/wsServerExample.rar 参考文献: http://www.ibm.com/developerwo ...
- webpack文件笔记
webpack.prod.conf.js里面的ExtractTextPlugin,把css文件提取出来,专门进行打包minify :压缩 依赖的第三方库打包到vendor.js里面 每次项目打包的时候 ...
- visual studio 2017 installer 安装包的安装必备组件设置
visual studio installer 2017 安装包的安装必备组件设置,默认设置只有net frmwork 4.6.1,如下图 这个时候如果打包安装,那么打出来的包一定需要先安装4.6. ...
- input text 去掉标签下拉提示
autocomplete 属性 autocomplete 属性规定输入字段是否应该启用自动完成功能. 自动完成允许浏览器预测对字段的输入.当用户在字段开始键入时,浏览器基于之前键入过的值,应该显示出在 ...
- Java集合(Collection)综述
1.集合简介 数学定义:一般地,我们把研究对象统称为元素.把一些元素组成的总体叫做集合. java集合定义:集合就是一个放数据的容器,准确的说是放数据对象引用的容器. java中通用集合类存放于jav ...
- 关系操作符 == != equals()
== 和!= //: object/test.java package object; import java.util.*; public class Test{ public static vo ...
- poj2442 堆应用
#include <cstdio> #include <cstring> #include <string> #include <vector> #in ...
- hdu1754splaytree区间查询
以前用线段树做的题..发现splay好神奇 splay的区间查询就是把那个区间移到两个节点之间进行操作即可,同时每次rotate不要忘记pushup #include<iostream> ...