Codeforces551 C. GukiZ hates Boxes
传送门:>Here<
$n$个位置上各放着$a_i$个箱子。有$m$个人位于初始位于下标0,每人每秒可以选择在当前位置上搬走一个箱子(即让一个箱子消失),或向前走一步。多个人可以同时位于一个位置。问最少几秒能搬完所有箱子。
$Solution$
二分时间+贪心验证。思维难度主要在验证上,想要最优就是让每一秒都不浪费。不浪费就是指:不傻站在哪儿,不跟别人抢一个箱子。如此我们每一个人单独考虑即可。这有点让我想到了那道很经典的“蚂蚁”,每个人都一样,其工作是可以等效的。
$Code$
long long
- /*By QiXingzhi*/
- #include <cstdio>
- #include <queue>
- #include <cstring>
- #include <algorithm>
- #define r read()
- #define Max(a,b) (((a)>(b)) ? (a) : (b))
- #define Min(a,b) (((a)<(b)) ? (a) : (b))
- using namespace std;
- typedef long long ll;
- #define int ll
- const int N = ;
- const int INF = ;
- inline int read(){
- int x = ; int w = ; register int c = getchar();
- while(c ^ '-' && (c < '' || c > '')) c = getchar();
- if(c == '-') w = -, c = getchar();
- while(c >= '' && c <= '') x = (x << ) +(x << ) + c - '', c = getchar();
- return x * w;
- }
- int a[N],b[N];
- int n,m,L,R,Mid,tot,ans,lim;
- inline bool judge(int x){
- int num = ;
- int res = ;
- for(int pile = ; pile <= lim; ++pile){
- res += a[pile];
- while(res + pile >= x){
- res -= x - pile;
- ++num;
- if(num > m) return ;
- }
- }
- if(num == m){
- return res <= ;
- }
- return ;
- }
- #undef int
- int main(){
- #define int ll
- // freopen(".in","r",stdin);
- n = r, m = r;
- for(int i = ; i <= n; ++i){
- a[i] = r;
- tot += a[i];
- if(a[i] != ) lim = i;
- }
- L = + lim, R = lim + tot;
- ans = -;
- while(L <= R){
- Mid = (L + R) / ;
- if(judge(Mid)){
- ans = Mid;
- R = Mid - ;
- }
- else{
- L = Mid + ;
- }
- }
- printf("%lld",ans);
- return ;
- }
Codeforces551 C. GukiZ hates Boxes的更多相关文章
- Codeforces Round #307 (Div. 2) C. GukiZ hates Boxes 贪心/二分
C. GukiZ hates Boxes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/551/ ...
- Codeforces 551C GukiZ hates Boxes(二分)
Problem C. GukiZ hates Boxes Solution: 假设最后一个非零的位置为K,所有位置上的和为S 那么答案的范围在[K+1,K+S]. 二分这个答案ans,然后对每个人尽量 ...
- Codeforces Round #307 (Div. 2) C. GukiZ hates Boxes 二分
C. GukiZ hates Boxes time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- codeforces 551 C GukiZ hates Boxes
--睡太晚了. ..脑子就傻了-- 这个题想的时候并没有想到该这样-- 题意大概是有n堆箱子从左往右依次排列,每堆ai个箱子,有m个人,最開始都站在第一个箱子的左边, 每个人在每一秒钟都必须做出两种选 ...
- CodeForces 551C - GukiZ hates Boxes - [二分+贪心]
题目链接:http://codeforces.com/problemset/problem/551/C time limit per test 2 seconds memory limit per t ...
- CF GukiZ hates Boxes 【二分+贪心】
Professor GukiZ is concerned about making his way to school, because massive piles of boxes are bloc ...
- 【24.67%】【codeforces 551C】 GukiZ hates Boxes
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- Codeforces 551C GukiZ hates Boxes 二分答案
题目链接 题意: 一共同拥有n个空地(是一个数轴,从x=1 到 x=n),每一个空地上有a[i]块石头 有m个学生 目标是删除全部石头 一開始全部学生都站在 x=0的地方 每秒钟每一个学生都 ...
- 二分+贪心 || CodeForces 551C GukiZ hates Boxes
N堆石头排成一列,每堆有Ai个石子.有M个学生来将所有石头搬走.一开始所有学生都在原点, 每秒钟每个学生都可以在原地搬走一块石头,或者向前移动一格距离,求搬走所有石头的最短时间. *解法:二分答案x( ...
随机推荐
- 微软Azure AspNetCore微服务实战第1期【补充2017-09-09活动】
2017年09月09日,冒着酷暑,我们在(上海徐汇)虹桥路3号港汇中心2座10层组织了一次微软Azure AspNetCore微服务实战活动. 由于前期工作繁忙,活动完成之后,没能及时发布相关信息,特 ...
- 五子棋(无AI winform gdi+)
之前无意间在博客园看到一篇用深度学习玩马里奥的文章,于是就想做这个小东西来测试人工智能算法(准备用PYTHON的库,对神经网络的梦已经做了好多年了,但是太难了,一直懒得动它),本来是想用WPF做UI, ...
- python读取/创建XML文件
Python中定义了很多处理XML的函数,如xml.dom,它会在处理文件之前,将根据xml文件构建的树状数据存在内存.还有xml.sax,它实现了SAX API,这个模块牺牲了便捷性,换取了速度和减 ...
- Joyride (spaf)
题目链接:https://codeforces.com/gym/101873/problem/C spaf的复杂度有点迷,按道理来说,一个简单的spaf在这题的复杂度是1e9,所以不敢写,然后用优先队 ...
- rabbitmq集群运维一点总结
说明:以下操作都以三节点集群为例,机器名标记为机器A.机器B.机器C,如果为双节点忽略机器C,如果为各多节点则与机器C操作相同 一.rabbitmq集群必要条件 1.1.绑定实体ip,即ip a所能查 ...
- AtCoder Beginner Contest 049 & ARC065 連結 / Connectivity AtCoder - 2159 (并查集)
Problem Statement There are N cities. There are also K roads and L railways, extending between the c ...
- Codeforces Round #534 (Div. 2)D. Game with modulo-1104-D(交互+二分+构造)
D. Game with modulo time limit per test 1 second memory limit per test 256 megabytes input standard ...
- JMeter压测分布式部署
监控JMeter压力机的性能
- Angular 自定义过滤器
<!DOCTYPE html><html ng-app="myApp"><head lang="en"> <meta ...
- ELK日志系统+x-pack安全验证
根据之前已经搭好的ELK系统,现在加一个x-pack插件上去,不然谁拿到ip和端口都可以访问elasticsearch和kibana. 要的效果如下:打开kibana界面的时候要让其输入用户名密码才能 ...