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 题意:中文题诶- 思路:枚举+贪心 一开始写的行和列同时 ...
随机推荐
- MongoDB的增删查改基本操作
MongoDB的增删查改基本操作 先决条件建库.建集合.建文档 连接mongo,如果连接不上什么连接拒绝,输入mongod命令,启动服务后 输入mongo show dbs 显示当前的所有的数据库 一 ...
- MR数据生成工具指向目录
mrDataTidy_SaveTwoDays.jar 原始路径 :D:\太原MR数据\一天数据整理 目标路径 : D:\MR现场数据整理\保存两天_整理后数据 例如 当前时间:2017-5-17 10 ...
- linux中结构体对齐【转】
转自:https://blog.csdn.net/suifengpiao_2011/article/details/47260085 linux中定义对齐字节 typedef struct sdk_ ...
- 技巧:Vim 的纵向编辑模式【转】
转自:https://www.ibm.com/developerworks/cn/linux/l-cn-vimcolumn/ 张 曜民 和 卢 丹2011 年 2 月 18 日发布 WeiboGoog ...
- odoo - context
得到整个context self.context_get() self.env['res.users'].context_get() 得到context里面对应的值 eg:得到flag的值 self. ...
- MyEclipse中如何配置默认jsp为UTF-8格式
- Spark学习之第一个程序打包、提交任务到集群
1.免秘钥登录配置: ssh-keygen cd .ssh touch authorized_keys cat id_rsa.pub > authorized_keys chmod 600 au ...
- mysql多线程插入速度与不同数据库之间的比较
package ThreadInsetMysql;import java.sql.Connection;import java.sql.DriverManager;import java.sql.SQ ...
- 纯 Java 开发 WebService 调用测试工具(wsCaller.jar)
注:本文来自hacpai.com:Tanken的<纯 Java 开发 WebService 调用测试工具(wsCaller.jar)>的文章 基于 Java 开发的 WebService ...
- java ServerSocket
public Socket accept() //等待连接,该方法阻塞 public void close() //关闭服务器套接字 ServerSocket只连一次的程序 /* this is se ...