agc 027 B - Garbage Collector
B - Garbage Collector
https://agc027.contest.atcoder.jp/tasks/agc027_b
题意:
x坐标轴上n个垃圾,有一个机器人在从原点,要清扫垃圾。原点有一个垃圾桶。机器人可以在x轴上左右移动,当移动到某个垃圾的位置上时,可以选择花费 X 点能量将它捡起来(也可以视而不捡)。机器人如果到达垃圾桶,则可以将它携带的垃圾花费 X 点能量倒出。机器人如果携带着 K 件垃圾移动一个单位距离,则需要消耗 (K+1)^2 点能量。问将所有垃圾全部弄到垃圾桶里面去所需消耗的最小能量。
分析:
贪心 + 推性质。
如果机器人一次将多个垃圾一起捡走,那么一定是从走到最后面,再回来。如果机器人第i个垃圾回来,花费为$pos_i \times (1 + 1) ^ 2 + pos_i = 5 pos_i$,如果在i前面再捡一个垃圾,新增加的花费为:$pos_j \times ((1 + 2) ^ 2 - (1 + 1) ^ 2) = 5 pos_j$ 同样再增加一个:$pos_k \times ((1 + 3) ^ 2 - (1 + 2) ^ 2) = 7pos_k$。所以有公式:
$F(i)=\left\{\begin{matrix} 5pos\ \ (i=1)\\ (2i+1)pos\ \ (i>1) \end{matrix}\right.$
表示第i个捡的垃圾的花费。
因为系数一样,所以每次捡多少应该都是一样的,枚举每次捡了多少。然后贪心的思路,让最远的点乘以系数最小的,就是让最远的k个点都是第一次拿,次远的k个点都是第二次拿...
代码:
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<iostream>
#include<cctype>
#include<set>
#include<vector>
#include<queue>
#include<map>
#define fi(s) freopen(s,"r",stdin);
#define fo(s) freopen(s,"w",stdout);
using namespace std;
typedef long long LL; inline LL read() {
LL x=,f=;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-;
for(;isdigit(ch);ch=getchar())x=x*+ch-'';return x*f;
} LL a[]; int main() {
int n = read();LL x = read();
for (int i=; i<=n; ++i) a[i] = read() + a[i - ];
LL ans = 1e18;
for (int k=; k<=n; ++k) {
LL sum = , now = ;
for (int i=n; i>=; i-=k) {
sum += (a[i] - a[max(, i - k)]) * max(now, 5ll), now += ;
if (sum >= ans) break;
}
ans = min(ans, sum + 1ll * (k + n) * x);
}
cout << ans;
return ;
}
agc 027 B - Garbage Collector的更多相关文章
- [GC]一个简单的Garbage Collector的实现
前言: 最近看了google的工程师写的一个非常简单的垃圾收集器,大概200多行C代码,感叹大牛总能够把复杂的东西通过很简单的语言和代码表达出来.为了增加自己的理解,决定把大牛的想法和代码分析一遍,与 ...
- 一个简单的Garbage Collector的实现
一个简单的Garbage Collector的实现 前言: 最近看了google的工程师写的一个非常简单的垃圾收集器,大概200多行C代码,感叹大牛总能够把复杂的东西通过很简单的语言和代码表达出来.为 ...
- AGC027 B - Garbage Collector 枚举/贪心
目录 题目链接 题解 代码 题目链接 AGC027 B - Garbage Collector 题解 对于一组选取组的最优方案为,走到一点,然后顺着路径往回取点 设选取点坐标升序为{a,b,c,d} ...
- 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配合使用的基本知识.你 ...
- Erlang Garbage Collector
Erlang Garbage Collector | Erlang Solution blog https://www.erlang-solutions.com/blog/erlang-garbage ...
- 提交并发量的方法:Java GC tuning :Garbage collector
三色算法,高效率垃圾回收,jvm调优 Garbage collector:垃圾回收器 What garbage? 没有任何引用指向它的对象 JVM GC回收算法: 引用计数法(ReferenceCou ...
- The Go Blog Getting to Go: The Journey of Go's Garbage Collector
Getting to Go: The Journey of Go's Garbage Collector https://blog.golang.org/ismmkeynote
随机推荐
- AngularJs学习笔记--I18n/L10n
原版地址:http://code.angularjs.org/1.0.2/docs/guide/i18n 一.I18n and L10n in AngularJS 1. 什么是I18n和L10n? 国 ...
- HTML和CSS实现常见的布局
https://segmentfault.com/a/1190000003931851#articleHeader15
- The transaction log for database 'XXX' is full due to 'ACTIVE_TRANSACTION'.
Msg 9002, Level 17, State 4, Line 4The transaction log for database 'Test' is full due to 'ACTIVE_TR ...
- dropout总结
1.伯努利分布:伯努利分布亦称“零一分布”.“两点分布”.称随机变量X有伯努利分布, 参数为p(0<p<1),如果它分别以概率p和1-p取1和0为值.EX= p,DX=p(1-p). 2. ...
- sublime text 插件及快捷键的使用
安装插件准备步骤: 1.先安装管理插件,插件必备:package control 1.按ctrl+` 调出console 2.在底部代码行粘贴以下代码并回车: import urllib2,os;pf ...
- 使用@AspectJ注解开发Spring AOP
一.实体类: Role public class Role { private int id; private String roleName; private String note; @Overr ...
- New Language Features in C# 6
Source:https://github.com/dotnet/roslyn/wiki/New-Language-Features-in-C%23-6 This document describes ...
- ARM Linux 内核 panic 之cache 一致性 ——Cortex-A9多核cache和TLB一致性广播
ARM Linux 内核 panic 之cache 一致性 ——Cortex-A9多核cache和TLB一致性广播 Cortex-A9的多喝CPU可以接收和执行一致性广播操作,当其使能并处于SMP模式 ...
- pt-online-schema-change在线修改表结构
工具简介 pt-osc模仿MySQL内部的改表方式进行改表,但整个改表过程是通过对原始表的拷贝来完成的,即在改表过程中原始表不会被锁定,并不影响对该表的读写操作.首先,osc创建与原始表相同的不包含数 ...
- .Net Core如何在任意位置获取配置文件的内容
前几天群里有人问,我想在程序里的任意位置读取appsetting.json里的配置,该怎么搞. 话不多说上源码 首先,要想读取配置文件我们要用到IConfiguration 接口,这个接口在Start ...