二分+贪心 || 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的取值上.那么先来谈如何验证.在已知时间的条件下,能否用一种 ...
随机推荐
- Codechef WEASELSC
WEASELSC code 给定一个高度图 a[1..n] ,要求你减少图中一些地方的高度,使得得到的图是一个不超过 K 级的楼梯,要求楼梯的面积最大(即得到的图中所有位置的高度之和最大). 这题题面 ...
- View Controller Programming Guide for iOS---(七)---Resizing the View Controller’s Views
Resizing the View Controller’s Views A view controller owns its own view and manages the view’s cont ...
- 019--python内置函数
一.内置高阶函数 map函数:接收两个数据 函数和序列,map()将函数调用'映射'到序列身上,并返回一个含有所有返回值的一个列表 num1 = [1,2,3,4,5] num2 = [5,4,3,2 ...
- linux中vfork对打开文件的处理
vfork和fork fork()函数是拷贝一个父进程的副本,拥有独立的代码段 数据段 堆栈空间 然而vfork是共享父亲进程的代码以及代码段 vfork是可以根据需要复制父进程空间,这样很大程度的提 ...
- clipse maven 项目 出现红色叹号 解决方法
感叹号代表jar包不全,看你是maven工程,pom.xml报错,应该是jar包路径不对.打开pom.xml文件,查看报错位置和报错信息. 缺失的jar包的配置去http://search.maven ...
- CentOS-用户的管理
用户组及配置文件 用户的类型 Linux是一个多用户.多任务的操作系统,如果要使用系统资源,就必须向系统管理员申请一个用户,通过这个用户进入系统,通过建立不同属性的用户实现不同的作用或权限,可以合理利 ...
- python 之 配置环境变量、通过pip 安装第三方库
配置环境变量 右击桌面上的“此电脑”—>“属性”—>“高级系统设置”—>右下角“环境变量”—>双击“系统变量”里的“Path”—>点击“新建”—>输入python的 ...
- 浅谈Thrift内部实现原理
http://dongxicheng.org/tag/thrift/ http://dongxicheng.org/search-engine/thrift-internals/ Thrift由两部分 ...
- Moctf--没时间解释了
记录一道简单的题目. 打开后就张这个样子,,然后看到url为index2.php---->所以我们把它改为index.php(用burp抓包才行,这是一个302跳转). 看到它提示我们要uplo ...
- C#XmlDocument输出字符串
XmlDocument xmlDoc = new XmlDocument(); //假定该xmlDoc已经有内容; MemoryStream streamXml = new MemoryStream( ...