二分+贪心 || CodeForces 551C GukiZ hates Boxes
#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的更多相关文章
- Codeforces 551C GukiZ hates Boxes(二分)
Problem C. GukiZ hates Boxes Solution: 假设最后一个非零的位置为K,所有位置上的和为S 那么答案的范围在[K+1,K+S]. 二分这个答案ans,然后对每个人尽量 ...
- CodeForces 551C - GukiZ hates Boxes - [二分+贪心]
题目链接:http://codeforces.com/problemset/problem/551/C time limit per test 2 seconds memory limit per t ...
- Codeforces 551C GukiZ hates Boxes 二分答案
题目链接 题意: 一共同拥有n个空地(是一个数轴,从x=1 到 x=n),每一个空地上有a[i]块石头 有m个学生 目标是删除全部石头 一開始全部学生都站在 x=0的地方 每秒钟每一个学生都 ...
- 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 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 ...
- 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 551 C GukiZ hates Boxes
--睡太晚了. ..脑子就傻了-- 这个题想的时候并没有想到该这样-- 题意大概是有n堆箱子从左往右依次排列,每堆ai个箱子,有m个人,最開始都站在第一个箱子的左边, 每个人在每一秒钟都必须做出两种选 ...
- Codeforces551 C. GukiZ hates Boxes
二分答案 + 贪心 传送门:$>here<$ $Solution$ 二分时间+贪心验证.思维难度主要在验证上,然而坑人的点却在n的取值上.那么先来谈如何验证.在已知时间的条件下,能否用一种 ...
随机推荐
- 【旧文章搬运】PspCidTable概述
原文发表于百度空间,2009-03-28========================================================================== PspCi ...
- 泛型Class<T>和 T. <T>
private T product; private Class<T> product; 这两个有什么区别呢,查了资料才知道,单独的T 代表一个类型 而 Class<T>代表这 ...
- Harbor安装部署--基于 Docker Distribution 的企业级 Registry 服务
harbor简介 Harbor 是一个企业级 Registry 服务.它对开源的 Docker Registry 服务进行了扩展,添加了更多企业用户需要的功能.Harbor 被设计用于部署一套组织内部 ...
- Codeforces - 1118D2 - Coffee and Coursework (Hard Version) - 二分
https://codeforces.com/problemset/problem/1118/D2 也是很好想的一个二分啦. 验证m的可行性的时候,肯定是把最多咖啡因的咖啡先尽可能平均分到每一天,因为 ...
- hihoCoder 1032
最长回文子串的O(1)算法Manacher算法 #include <iostream> #include <stdio.h> #include <string.h> ...
- sql server编写通用脚本自动统计各表数据量心得
工作过程中,如果一个数据库的表比较多,手工编写统计脚本就会比较繁琐,于是摸索出自动生成各表统计数据量脚本的通用方法,直接上代码: /* 脚本来源:https://www.cnblogs.com/zha ...
- 洛谷P2585 [ZJOI2006]三色二叉树(树形dp)
传送门 设$dp[u][i]$表示点$u$颜色为$i$时最多(最少)的绿点个数(这里用$0$表示绿点) 然后直接用树形dp就可以了 记得把情况讨论清楚 //minamoto #include<b ...
- 第八篇 .NET高级技术之字符串暂存池(缓冲池)
字符串不可变性,字符串的‘暂存池’两个特性 字符串是引用类型,程序中会存在大量的字符串对象,如果每次都创建一个字符串对象,会比较浪费内存.性能低,因此CLR做了“暂存池”(拘留池,缓冲池,暂存池),在 ...
- 深入解读docker网络与kubernetes网络
前言:你是否学习使用k8s很久很久了可是对于网络这块仍旧似懂非懂呢? 您是否对网上一堆帖子有如下的抱怨: 打开多个博客,然后发现有区别么? 明显是直译过来的,越看越迷糊 “因为xxx,所以yyy”,. ...
- JSR 303 - Bean Validation 模型验证
类是转载的,不知道转的哪里的. 此类依赖 JSR 303 – Bean Validation, Hibernate Validator. 代码不能直接运行.意会一下.自己改改. import com. ...