传送门:>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的更多相关文章

  1. 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/ ...

  2. Codeforces 551C GukiZ hates Boxes(二分)

    Problem C. GukiZ hates Boxes Solution: 假设最后一个非零的位置为K,所有位置上的和为S 那么答案的范围在[K+1,K+S]. 二分这个答案ans,然后对每个人尽量 ...

  3. 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 ...

  4. codeforces 551 C GukiZ hates Boxes

    --睡太晚了. ..脑子就傻了-- 这个题想的时候并没有想到该这样-- 题意大概是有n堆箱子从左往右依次排列,每堆ai个箱子,有m个人,最開始都站在第一个箱子的左边, 每个人在每一秒钟都必须做出两种选 ...

  5. CodeForces 551C - GukiZ hates Boxes - [二分+贪心]

    题目链接:http://codeforces.com/problemset/problem/551/C time limit per test 2 seconds memory limit per t ...

  6. CF GukiZ hates Boxes 【二分+贪心】

    Professor GukiZ is concerned about making his way to school, because massive piles of boxes are bloc ...

  7. 【24.67%】【codeforces 551C】 GukiZ hates Boxes

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. Codeforces 551C GukiZ hates Boxes 二分答案

    题目链接 题意:  一共同拥有n个空地(是一个数轴,从x=1 到 x=n),每一个空地上有a[i]块石头  有m个学生  目标是删除全部石头  一開始全部学生都站在 x=0的地方  每秒钟每一个学生都 ...

  9. 二分+贪心 || CodeForces 551C GukiZ hates Boxes

    N堆石头排成一列,每堆有Ai个石子.有M个学生来将所有石头搬走.一开始所有学生都在原点, 每秒钟每个学生都可以在原地搬走一块石头,或者向前移动一格距离,求搬走所有石头的最短时间. *解法:二分答案x( ...

随机推荐

  1. R语言绘制茎叶图

    与直方图相比,茎叶图更能细致的看出数据分布情况! 代码: > x<-c(25, 45, 50, 54, 55, 61, 64, 68, 72, 75, 75,+ 78, 79, 81, 8 ...

  2. R语言绘制QQ图

    无论是直方图还是经验分布图,要从比较上鉴别样本是否处近似于某种类型的分布是困难的 QQ图可以帮我们鉴别样本的分布是否近似于某种类型的分布 R语言,代码如下: > qqnorm(w);qqline ...

  3. Java面试题详解三:比较器

    一,Comparable和Comparator1.Comparable可以认为是一个内比较器,实现了Comparable接口的类有一个特点,就是这些类是可以和自己比较.Comparable接口中只有一 ...

  4. MySQL分页时统计总记录行数并使用limit返回固定数目的记录

    需求很简单:假设有一个user表,表中实际上有10000条数据,但是我不知道有多少条,我要从数据库中每次取20条数据显示,那么怎么完成呢? 方案一: 首先执行一个 select count(*) as ...

  5. python Drools

    python Drools - 国际版 Binghttps://cn.bing.com/search?q=python+Drools&qs=n&FORM=BESBTB&sp=- ...

  6. 如何入门vue之一

    入门vue 首先从vue的指令开始学起. vue的指令: v-if  根据是否得到的布尔值进行是否显示. v-show:根据是否得到的布尔值是否显示.不同的地方在于隐藏是style隐藏. v-on 监 ...

  7. yolo buffer is too small for requested array

    yolo.cfg 与 yolo.weights 版本一定要对应, darknet链接 https://github.com/pjreddie/darknet 下载后在cfg文件夹下找到yolov2的配 ...

  8. C#设计模式之6:抽象工厂模式

    前面分析了简单工厂模式和工厂方法模式,接着来看一下抽象工厂模式,他与工厂方法模式有一些相似的地方,也有不同的地方. 先来看一个不用工厂方法模式实现的订购披萨的代码: 对象依赖的问题:当你直接实例化一个 ...

  9. CMake--List用法

    list(LENGTH <list><output variable>) list(GET <list> <elementindex> [<ele ...

  10. VS code常用快捷方式—转载

    http://www.cnblogs.com/weihe-xunwu/p/6687000.html