N堆石头排成一列,每堆有Ai个石子。有M个学生来将所有石头搬走。一开始所有学生都在原点, 每秒钟每个学生都可以在原地搬走一块石头,或者向前移动一格距离,求搬走所有石头的最短时间。
*解法:二分答案x(时间),即每位学生均有x秒的时间,模拟搬石头过程看能否搬完即可(一个人一个人计算,每个人均尽力完成任务即可)。
记得开longlong
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
#define SZ 100005
#define INF 1e15+10
long long a[SZ], b[SZ];
int n, m;
int check(long long x)
{
int flag = ;
long long p = , t;//时间x
for(int i = ; i <= n; i++) b[i] = a[i];
for(int i = ; i <= m; i++)
{
t = x - p;
while(t > && p <= n)
{
if(t > b[p]) {t -= b[p]; b[p] = ; p++; t--;}
//do{p++; t--;} while(b[p] == 0);
else if(t == b[p]) {b[p] = ; p++; t = ;}
else {b[p] -= t; t = ;}
}
}
for(int i = ; i <= n; i++)
if(b[i] > ) flag = ;
if(!flag) return ;
return ;
}
int main()
{
scanf("%d %d", &n, &m);
for(int i = ; i <= n; i++)
scanf("%lld", &a[i]);
long long l = , r = INF, mid;
while(r > l)
{
mid = (r + l) / ;
if(check(mid)) r = mid;
else l = mid + ;
}
printf("%lld\n", r);
return ;
}

二分+贪心 || CodeForces 551C GukiZ hates Boxes的更多相关文章

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

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

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

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

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

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

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

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

  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 551 C GukiZ hates Boxes

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

  9. Codeforces551 C. GukiZ hates Boxes

    二分答案 + 贪心 传送门:$>here<$ $Solution$ 二分时间+贪心验证.思维难度主要在验证上,然而坑人的点却在n的取值上.那么先来谈如何验证.在已知时间的条件下,能否用一种 ...

随机推荐

  1. h.264的POC计算(转载)

    转自:http://www.cnblogs.com/TaigaCon/p/3551001.html 本文参考自http://wenku.baidu.com/link?url=ZPF0iSKzwLQg_ ...

  2. Oracle Escape

    select * from tablewhere col like '%\_'escape'\'

  3. python __builtins__ license类 (41)

    41.'license', 许可证,执照 class _Printer(builtins.object) | interactive prompt objects for printing the l ...

  4. bzoj 3027: [Ceoi2004]Sweet【生成函数+组合数学】

    首先根据生成函数的套路,这个可以写成: \[ \prod_{i=1}^{n}(1+x^1+x^2+...+x^{c[i]}) \] 然后化简 \[ =\prod_{i=1}^{n}\frac{1-x^ ...

  5. LuoguP2822 组合数问题(组合数,二维前缀和)

    P2822 组合数问题 输入输出样例 输入样例#1: 复制 1 2 3 3 输出样例#1: 复制 1 输入样例#2: 复制 2 5 4 5 6 7 输出样例#2: 复制 0 7 说明 [样例1说明] ...

  6. 富文本编辑器vue2-editor实现全屏功能

    vue2-editor非常不错,可惜并未带全屏功能,自己实现了一个,供大家参考. 实现思路:自定义模块. 1. 定义全屏模块Fullscreen /** * 编辑器的全屏实现 */ import no ...

  7. 2017年“嘉杰信息杯” 中国大学生程序设计竞赛全国邀请赛 Highway

    Highway Accepted : 122   Submit : 393 Time Limit : 4000 MS   Memory Limit : 65536 KB Highway In ICPC ...

  8. 暴力 BestCoder Round #41 1001 ZCC loves straight flush

    题目传送门 /* m数组记录出现的花色和数值,按照数值每5个搜索,看看有几个已满足,剩下 5 - cnt需要替换 ╰· */ #include <cstdio> #include < ...

  9. HTTP提交方式之PUT详细介绍及POST和PUT的区别

    Http定义了与 服务器的交互方法,其中除了一般我们用的最多的GET,POST 其实还有PUT和DELETE 根据RFC2616标准(现行的HTTP/1.1)其实还有OPTIONS,GET,HEAD, ...

  10. 搜狐前端css常用命名