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 题意:中文题诶- 思路:枚举+贪心 一开始写的行和列同时 ...
随机推荐
- AT91RM9200---定时器简介
1.前言 系统定时器模块集成了3个不同的定时器 一个周期性间隔的定时器,用来为操作系统设置时基 一个看门狗定时器,可用于软件死锁时进行系统复位 一个实时时钟计数器用来记录流逝的时间 系统定时器时钟 这 ...
- [转]Linux下的链接脚本基础
[转]http://linux.chinaunix.net/techdoc/beginner/2009/08/12/1129972.shtml 1. 前言 (1)每一个链接过程都由链接脚本(linke ...
- telnet不能用!!!提示:-bash: telnet: command not found
1.[root@localhost ~]# telnet 2. 查询了是否安装Telnet包,结果如下: telnet-server-0.17-47.el6.i686 [xinetd (pid ...
- 001_深度剖析什么是 SLI、SLO和SLA?
前言 SLO和SLA是大家常见的两个名词:服务等级目标和服务等级协议. 云计算时代,各大云服务提供商都发布有自己服务的SLA条款,比如Amazon的EC2和S3服务都有相应的SLA条款.这些大公司的S ...
- linux unzip 中文乱码解决方法
引自:https://blog.csdn.net/abyjun/article/details/48344379 unzip -O CP936 xxx.zip (用GBK, GB18030也可以)
- 1. let 和 const 命令
一.简单认识 1. 用let来声明变量,变量作用域就在{}(块级作用域)中 2. 用const声明变量,变量值不可更改 3. 增加了let以后,在声明变量时应该多考虑一下变量的用途,是否希望只在当前代 ...
- passive 的事件监听器(转载)
passive 的事件监听器 很久以前,addEventListener() 的参数约定是这样的: addEventListener(type, listener, useCapture) 后来,最后 ...
- Redis五大数据类型以及操作
目录: 一.redis的两种链接方式 二.redis的字符串操作(string) 三.redis的列表操作(list) 四.redis的散列表操作(类似于字典里面嵌套字典) 五.redis的集合操作( ...
- C++ code:main参数
main函数的参数结构为两项参数: int main(int argc,char** argv){……} main的参数由操作系统传递,所以比较特殊.两个形参名一般是采用习惯名称argc和argv,表 ...
- Linear Algebra(未完待续)
[矩阵消元] The result of multiplying a matrix by some vector is a combination of the columns of the matr ...