codeforces 551 C GukiZ hates Boxes
……睡太晚了。
。。脑子就傻了……
这个题想的时候并没有想到该这样……
题意大概是有n堆箱子从左往右依次排列,每堆ai个箱子,有m个人,最開始都站在第一个箱子的左边,
每个人在每一秒钟都必须做出两种选择中的一种:1若他的位置有箱子则搬走一个箱子,2往右走一步。
问把全部箱子都搞掉的最少时间……
非常显然二分一下答案,若为x秒,则每一个人都有x秒。一个一个排出去搬。看是否可以搬完……
我居然没想到……
#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<climits>
#include<list>
#include<iomanip>
#include<stack>
#include<set>
using namespace std;
typedef long long ll;
int a[100010];
bool isok(int n,int m,ll x)
{
ll t=x;
for(int i=0;i<n;i++)
{
int re=a[i];
ll t1=t-i-1;
if(t1<0)
{
if(m==0)
return 0;
t1=x-i-1;
t=x;
m--;
}
if(re>0)
{
if(t1>=re)
t-=re;
else
{
re-=t1;
t1=x-i-1;
t=x;
int t2=re/t1;
re-=t2*t1;
if(re>0)
{
t2++;
t-=re;
}
else
t=0;
m-=t2;
if(m<0)
return 0;
}
}
}
return 1;
}
int main()
{
int n,m;
cin>>n>>m;
for(int i=0;i<n;i++)
cin>>a[i];
for(int i=n-1;i>-1;i--)
if(a[i]!=0)
{
n=i+1;
break;
}
ll l=n+1,r=ll(1e15);
while(l<=r)
{
ll md=l+r>>1;
if(isok(n,m-1,md))
r=md-1;
else
l=md+1;
}
cout<<l;
}
2 seconds
256 megabytes
standard input
standard output
Professor GukiZ is concerned about making his way to school, because massive piles of boxes are blocking his way.
In total there are n piles of boxes, arranged in a line, from left to right, i-th
pile (1 ≤ i ≤ n) containing ai boxes.
Luckily, m students are willing to help GukiZ by removing all the boxes from his way. Students are working simultaneously. At time 0,
all students are located left of the first pile. It takes one second for every student to move from this position to the first pile, and after that, every student must start performing sequence of two possible operations, each taking one second to complete.
Possible operations are:
- If i ≠ n, move from pile i to
pile i + 1; - If pile located at the position of student is not empty, remove one box from it.
GukiZ's students aren't smart at all, so they need you to tell them how to remove boxes before professor comes (he is very impatient man, and doesn't want to wait). They ask you to calculate minumum time t in
seconds for which they can remove all the boxes from GukiZ's way. Note that students can be positioned in any manner after t seconds,
but all the boxes must be removed.
The first line contains two integers n and m (1 ≤ n, m ≤ 105),
the number of piles of boxes and the number of GukiZ's students.
The second line contains n integers a1, a2, ... an (0 ≤ ai ≤ 109)
where ai represents
the number of boxes on i-th pile. It's guaranteed that at least one pile of is non-empty.
In a single line, print one number, minimum time needed to remove all the boxes in seconds.
2 1
1 1
4
3 2
1 0 2
5
4 100
3 4 5 4
5
First sample: Student will first move to the first pile (1 second), then remove box from first pile (1 second),
then move to the second pile (1 second) and finally remove the box from second pile (1 second).
Second sample: One of optimal solutions is to send one student to remove a box from the first pile and a box from the third pile, and send another student to remove a box from the third pile. Overall, 5 seconds.
Third sample: With a lot of available students, send three of them to remove boxes from the first pile, four of them to remove boxes from the second pile, five of them to remove boxes from the third pile, and four of them to remove boxes from the fourth pile.
Process will be over in 5 seconds, when removing the boxes from the last pile is finished.
codeforces 551 C GukiZ hates Boxes的更多相关文章
- 【24.67%】【codeforces 551C】 GukiZ hates Boxes
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 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 D. GukiZ and Binary Operations
\(>Codeforces \space 551 D. GukiZ and Binary Operations<\) 题目大意 :给出 \(n, \ k\) 求有多少个长度为 \(n\) ...
- 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 551C GukiZ hates Boxes
N堆石头排成一列,每堆有Ai个石子.有M个学生来将所有石头搬走.一开始所有学生都在原点, 每秒钟每个学生都可以在原地搬走一块石头,或者向前移动一格距离,求搬走所有石头的最短时间. *解法:二分答案x( ...
- CF GukiZ hates Boxes 【二分+贪心】
Professor GukiZ is concerned about making his way to school, because massive piles of boxes are bloc ...
随机推荐
- 打印 Go 结构体(struct)信息:fmt.Printf("%+v", user)
package main import "fmt" // 用户 type User struct { Id int Name string Age int } func main( ...
- JVM Internals
http://blog.jamesdbloom.com/JVMInternals.html http://blog.csdn.net/column/details/talk-about-jvm.htm ...
- Unity3d学习笔记记录
1.发布到 ipad字体显示不出来,改变Position位置的Z轴为-1 2.发布打包有问题,记得用户权限有没有设置 3.ipad4分辨率:2048*1536 4.调整界面大小,尽量调整底下子对象位置 ...
- 如何:声明、实例化和使用委托(C# 编程指南)
委托的声明如下所示: C# public delegate void Del<T>(T item); public void Notify(int i) { } C# Del< ...
- delphi 取上级目录
var S: string;begin S := 'c:\aa\bb\cc\dd\abc.exe'; ShowMessage(ExtractFileDir(ExtractFileDir(S))) ...
- 自己动手实现一个MVVM库
我们知道的,常见的数据绑定的实现方法 1.数据劫持(vue):通过Object.defineProperty() 去劫持数据每个属性对应的getter和setter2.脏值检测(angular):通过 ...
- Flex+blazeds实现与mySQL数据库的连接(已成功实现此文的例子)
http://bdk82924.iteye.com/blog/1067285 几个下载地址 blazeds_turnkey_3-0-0-544.zip 下载地址:http://download.mac ...
- rest api上传和下载文件
rest api上传和下载文件 function FileToString(AFileName: string): string; var LMemoryStream: TMemoryStream; ...
- Java 集合系列之 Vector详细介绍(源码解析)和使用示例
Vector简介 Vector 是矢量队列,它是JDK1.0版本添加的类.继承于AbstractList,实现了List, RandomAccess, Cloneable这些接口. Vector 继承 ...
- Safari支不支持HTML5录音? 现在浏览器中最好的解决方案是WebRTC下的 navigator.getUserMedia API。
先放结论:Safari支不支持HTML5录音? ——据我调查,不支持. 现在浏览器中最好的解决方案是WebRTC下的 navigator.getUserMedia API. 可是当使用Can I us ...