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 题意:中文题诶- 思路:枚举+贪心 一开始写的行和列同时 ...
随机推荐
- 腾讯云外网IP直通后,遇到网络问题
通过内网机器,先重启网卡 service network restart cd /usr/local/etc ./modify_route.sh
- 如何在linux系统下配置无线网卡?【转】
转自:http://www.jb51.net/LINUXjishu/61315.html 本文介绍在Linux 命令行界面中手动配置无线网卡的方法.目前流行的多数发行版都支持用图形界面的network ...
- dubbo系列三、架构介绍及各模块关系
一.整体设计 图例说明: 图中左边淡蓝背景的为服务消费方使用的接口,右边淡绿色背景的为服务提供方使用的接口,位于中轴线上的为双方都用到的接口. 图中从下至上分为十层,各层均为单向依赖,右边的黑色箭头代 ...
- openstack swift节点安装手册1-节点配置
本文参照官方教程:http://docs.openstack.org/project-install-guide/object-storage/draft/environment-networking ...
- python下的socket常用方法举例
python下的socket 1.简单的server和client端的socket代码 server.py: #!/usr/bin/env python #_*_ coding:utf-8 _*_ i ...
- Account的简单架构
前几天,有园友私下问我,博客中的AccountDemo后端架构为什么是那样的,是不是分层太多太冗余,故这里简单介绍下.先看解决方案工程截图: 每个工程的含义,见https://www.cnblogs. ...
- sklearn调参(验证曲线,可视化不同参数下交叉验证得分)
一 . 原始方法: 思路: 1. 参数从 0+∞ 的一个 区间 取点, 方法如: np.logspace(-10, 0, 10) , np.logspace(-6, -1, 5) 2. 循环调用cr ...
- bzoj 2142
数论大集合 只要你做完了这道题,除了线性筛和降幂公式以外,所有数论noip知识点就都会了... 题意:求C(n,∑w)*C(∑w,w1)*C(∑w-w1,w2).....mod p(不保证p为质数) ...
- Python实现进度条功能
Python实现进度条功能 import sys, time def progress(percent, width=50): # 设置进度条的宽度 if percent >= 100: # 当 ...
- 怎么用pr(Premiere)给视频添加水印
自己辛辛苦苦剪切的视频,不添加水印,别人肯定会搬走的,作为对视频付出时间的你肯定不想看见这样的事情,下面一起来看看怎么用pr给视频添加水印吧 工具/原料 水印 pr 方法/步骤 首先打 ...