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( ...
随机推荐
- Leetcode -- 394. Decode String
Given an encoded string, return it's decoded string. The encoding rule is: k[encoded_string], where ...
- H5 13-子元素选择器
13-子元素选择器 p{ color: red; } */ /* #identity>p{ color: blue; } */ div>ul>li>p{ color: purp ...
- 03-HTML之body标签
body标签 HTML标签按作用主要分为两类:字体标签和排版标签 HTML标签按级别主要分为两类:文本级标签和容器级标签 文本级标签:p.span.a.b.i.u.em.文本标签里只能放文字.图片.表 ...
- p211有界自共轭算子T是实数集合的子集
对条件 取非 是 ∉谱集合的实数 才对 现在是 入 属于正则点集 他 然后 又说T 的谱是实数 这不矛盾吗 这里根据 必要性 推出 蓝色和红色矛盾 矛盾就是 这是谱点 然 ...
- stark组件之pop页面,按钮,url,页面
1.Window open() 方法 2.admin的pop添加按钮 3.stark之pop功能 3.知识点总结 4.coding代码 1.Window open() 方法 效果图 2.adm ...
- 企业级分布式应用服务EDAS _Dubbo商业版_微服务PaaS平台 【EDAS Serverless 运维 创业】
企业级分布式应用服务EDAS _Dubbo商业版_微服务PaaS平台_分布式框架 - 阿里云https://www.aliyun.com/product/edas?source_type=yqzb_e ...
- 【Python3练习题 005】输入三个整数x,y,z,请把这三个数由小到大输出
import re x, y, z = re.split(',| |,| ', input('请输入3个数字,用逗号或空格隔开:'))x, y, z = int(x), int(y), int(z) ...
- [转帖]SAP进阶:再论SAP权限
SAP进阶:再论SAP权限 http://blog.vsharing.com/MilesForce/A634100.html 网上有不少关于权限的文章,多是转来转去,COPY的台湾某个人N年前的PPT ...
- [转帖]Windows注册表内容详解
Windows注册表内容详解 来源:http://blog.sina.com.cn/s/blog_4d41e2690100q33v.html 对 windows注册表一知半解 不是很清晰 这里学习一下 ...
- WebService实例-CRM系统提供WebService实现用户注册功能
<—start—> 编写crm的webservice接口,实现客户信息保存操作.在CustomerService接口中新增一个服务接口,用于添加客户注册的信息. @Path("/ ...