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
随机推荐
- 我上线的android版app
把自己开发的几个小的app上线了,在自己的博客中推广一下吧: 聊天兔子: 下载地址:http://android.myapp.com/myapp/detail.htm?apkName=com.fuly ...
- BZOJ2333:[SCOI2011]棘手的操作(Splay)
Description 有N个节点,标号从1到N,这N个节点一开始相互不连通.第i个节点的初始权值为a[i],接下来有如下一些操作: U x y: 加一条边,连接第x个节点和第y个节点 A1 x v: ...
- 第三章.搭建MyBatis工程环境
1.数据库的准备: 数据库: create DATABASE mybatis: 数据表: CREATE TABLE `user` ( `id` int(10) NOT NULL AUTO_INCREM ...
- Kali-linux安装并配置NVIDIA显卡驱动
显卡驱动程序就是用来驱动显卡的程序,它是硬件所对应的软件.驱动程序即添加到操作系统中的一小块代码,其中包含有关硬件设备的信息.有了此信息,计算机就可以与设备进行通信.驱动程序是硬件厂商根据操作系统编写 ...
- tensorflow的一些函数
1.tf.constant(value,dtype=None,shape=None,name='Const') 注意这个函数创造的是一个常数tensor,而不是一个具体的常数 value:即可以是li ...
- 微信小程序,搜索结果关键词高亮 wxml不能动态识别html标签
wxml中使用rich-text标签放置动态html标签 js:
- Knowledge Point 20180309 字符串常量池与String,intern()
引言 什么都先不说,先看下面这个引入的例子: public static void test4(){ String str1 = new String("SEU") + new S ...
- jQuery入门简单实现反选与全选
//html代码<input type="checkbox" id= 'all' value="全选"> 选择全部 一键上路 <input t ...
- HDU1398 Square Coins(生成函数)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
- Bash游戏(51Nod - 1046)
20180603 有一堆石子共有N个.A B两个人轮流拿,A先拿.每次最少拿1颗,最多拿K颗,拿到最后1颗石子的人获胜.假设A B都非常聪明,拿石子的过程中不会出现失误.给出N和K,问最后谁能赢得比赛 ...