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( ...
随机推荐
- 微服务之:从零搭建ocelot网关和consul集群
介绍 微服务中有关键的几项技术,其中网关和服务服务发现,服务注册相辅相成. 首先解释几个本次教程中需要的术语 网关 Gateway(API GW / API 网关),顾名思义,是企业 IT 在系统边界 ...
- JS 异步系列 —— Promise 札记
Promise 研究 Promise 的动机大体有以下几点: 对其 api 的不熟悉以及对实现机制的好奇; 很多库(比如 fetch)是基于 Promise 封装的,那么要了解这些库的前置条件得先熟悉 ...
- Oracle 一个用户将表权限赋给另一个用户
原文地址:https://blog.csdn.net/u012129031/article/details/76218764 1.将用户user1的表权限赋给用户user2 select 'gra ...
- javaMail发邮件,激活用户账号
用javamail实现注册用户验证邮箱功能.用户注册后随机生成一个uuid作为用户的标识,传递给用户然后作为路径参数.发送html的内容到用户注册的邮箱里,若用户点击后去往的页面提交username和 ...
- javascript重定向页面并用post方法传递消息
javascript中重定向页面得方法很多,同时能传递消息的也不少:但可用post方法传递的我只找到两种: 第一种方法:用document.write在 JavaScript函数中,用document ...
- Python_匿名函数
匿名函数:为了解决那些功能很简单的需求而设计的一句话函数. 代码如下: 1 正常函数: 2 3 def calc(n): 4 5 return n ** n 6 7 print(calc(10)) 8 ...
- hadoop和java 配置环境变量的的tar
第一步:打开工具上传tar包 如下图 第二步:在文件路径下查看是否上传成功 第三步:解压tar包 tar -zxvf hadoop.2.6.5.tar.gz 第四步:配置环 ...
- MySQL数据库导入错误:ERROR 1064 (42000) 和 ERROR at line xx:
https://www.cnblogs.com/yeahgis/p/4358973.html mysql -hlocalhost -uroot -proot --default-character-s ...
- 【Python3练习题 005】输入三个整数x,y,z,请把这三个数由小到大输出
import re x, y, z = re.split(',| |,| ', input('请输入3个数字,用逗号或空格隔开:'))x, y, z = int(x), int(y), int(z) ...
- select非group by字段的方法
只需要将非group by字段放进函数中即可: