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个点都是第二次拿...

代码:

 1 #include<cstdio>
 2 #include<algorithm>
 3 #include<cstring>
 4 #include<cmath>
 5 #include<iostream>
 6 #include<cctype>
 7 #include<set>
 8 #include<vector>
 9 #include<queue>
10 #include<map>
11 #define fi(s) freopen(s,"r",stdin);
12 #define fo(s) freopen(s,"w",stdout);
13 using namespace std;
14 typedef long long LL;
15
16 inline LL read() {
17     LL x=0,f=1;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch==‘-‘)f=-1;
18     for(;isdigit(ch);ch=getchar())x=x*10+ch-‘0‘;return x*f;
19 }
20
21 LL a[200005];
22
23 int main() {
24     int n = read();LL x = read();
25     for (int i=1; i<=n; ++i) a[i] = read() + a[i - 1];
26     LL ans = 1e18;
27     for (int k=1; k<=n; ++k) {
28         LL sum = 0, now = 3;
29         for (int i=n; i>=1; i-=k) {
30             sum += (a[i] - a[max(0, i - k)]) * max(now, 5ll), now += 2;
31             if (sum >= ans) break;
32         }
33         ans = min(ans, sum + 1ll * (k + n) * x);
34     }
35     cout << ans;
36     return 0;
37 }

原文地址:https://www.cnblogs.com/mjtcn/p/9720076.html

时间: 2024-08-05 04:00:39

agc 027 B - Garbage Collector的相关文章

c++ simple &quot;Garbage Collector&quot;

The idea is to create a Ptr type that acts like a reference in Java. And A Garbage Collector (MemMgr) type that acts like a garbage collector in Java. Just a toy. :D main.cpp 1 #include "MemMgr.h" 2 3 #include <iostream> 4 5 using namespac

The Go Blog Getting to Go: The Journey of Go&#39;s Garbage Collector

Getting to Go: The Journey of Go's Garbage Collector https://blog.golang.org/ismmkeynote The Go Blog Getting to Go: The Journey of Go's Garbage Collector 原文地址:https://www.cnblogs.com/yuanjiangw/p/12179561.html

G1 Garbage Collector and Shenandoah

http://www.diva-portal.se/smash/get/diva2:754515/FULLTEXT01.pdf https://is.muni.cz/th/ifz8g/GarbageCollection.pdf?so=nx https://www.researchgate.net/publication/306112816_Shenandoah_An_open-source_concurrent_compacting_garbage_collector_for_OpenJDK h

Java_garbage collector

摘自:http://blog.csdn.net/java2000_wl/article/details/8030172 HotSpot JVM垃圾收集器 上面有7中收集器,分为两块,上面为新生代收集器,下面是老年代收集器.如果两个收集器之间存在连线,就说明它们可以搭配使用. Serial(串行GC)收集器_Serial GC Serial收集器是一个新生代收集器,单线程执行,使用复制算法.它在进行垃圾收集时,必须暂停其他所有的工作线程(用户线程).是Jvm client模式下默认的新生代收集器.

Understanding .net CLR garbage collection--(踏踏实实学好.Net系列)

引言 内存管理是计算机科学中一个相当复杂而有趣的领域.在计算机诞生的这几十年间,内存的管理的技术不断进步,使系统能够更加有效地利用内存这一计算机必不可少的资源. 一般而言,内存管理可以分为三类:硬件管理(如TLB),操作系统管理(如Buddy System,Paging,Segmentation),应用程序管理(如C++,Java,.net的内存管理机制).鉴于篇幅和笔者水平的限制,本文只涉及了内存管理的很小一部分,即.net中的内存管理方法..net是一个当代的应用程序框架,采用了内存自动管理

Advanced .NET Debugging: Managed Heap and Garbage Collection(转载,托管堆查内存碎片问题解决思路)

原文地址:http://www.informit.com/articles/article.aspx?p=1409801&seqNum=4 Debugging Managed Heap Fragmentation Earlier in the chapter, we described a phenomenon known as heap fragmentation, in which free and busy blocks are arranged and interleaved on th

garbage collection - 垃圾收集

Professional.JavaScript.for.Web.Developers.3rd.Edition.Jan.2012 JavaScript is a garbage-collected language, meaning that the execution environment is responsible for managing the memory required during code execution. In languages like C and C++, kee

Oracle JVM Garbage Collectors Available From JDK 1.7.0_04 And After

Jack Shirazi tells you what garbage collectors and garbage collector combinations are available from the Oracle Java 7 update 4 JVM and onwards, including Java 8 and Java 9. Published June 2012, Updated September 2015, Author Jack Shirazi --From http

Tuning Java Garbage Collection for Spark Applicati

This is a guest post from our friends in the SSG STO Big Data Technology group at Intel. Join us at the Spark Summit to hear from Intel and other companies deploying Spark in production.  Use the code Databricks20 to receive a 20% discount! Spark is