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 ...
随机推荐
- Windows XP UDF 2.5 补丁,播放蓝光ISO光盘必备
蓝光光盘的文件系统是UDF2.5,Windows XP及以下的操作系统默认不能支持这个文件系统.当我们在XP系统中使用蓝光光盘或蓝光ISO文件时,就会提示“Windows不能从此盘读取,此盘可能已损坏 ...
- 布局控件Grid
XAML概述 Silverlight的控件绘制是由XAML语言进行支持的.什么是XAML语言? 简单的说,XAML(Extensible Application Markup Language )是一 ...
- 怎样在xcode5中使用低版本sdk,解决兼容ios7ui问题
问题 令人头疼的是,xcode每次升级都会使用最新版本的sdk,而且只有最新版本的sdk,对之前老版本的sdk都没有默认安装,这搞的最近我很头疼, 最近我升级到Xcode5.0版本,编译后运行后,在i ...
- ANDROID DisplayManager 服务解析一
from://http://blog.csdn.net/goohong/article/details/8536102 http://www.tuicool.com/articles/FJVFnu A ...
- Netty Pipeline、channel、Context之间的数据流向
以下所绘制图形均基于Netty4.0.28版本. 一.connect(outbound类型事件) 当用户调用channel的connect时,会发起一个outbound类型的事件,该事件将在pipe ...
- C++ 继承体系中的名称覆盖
首先一个简单的样例: int x; int f() { double x; cin >> x; return x; } 在上述代码中.函数f的局部变量x掩盖了全局变量x.这得从 " ...
- java项目实现流水号自动增长
项目中有一个规则编号字段,从1开始,编号长度为5位,那么第一条数据编号就是00001. 实现的基本思路就是项目启动时,从数据库获取当前最大值,作为静态变量存储: 业务获取新的编码,考虑并发问题,获取编 ...
- 关于 java.lang.IllegalStateException: invocation
由于在 quartz 的 job 中有引用其它 service(这个 service 中又引用了 inv.getRequest() ) ,所以报以上错误了...还没有找到解决办法
- Lua date format
网上有比较复杂的方法:Date Formatting Functions 写了一个非常简单的代码 1: function formatDate(seconds, dateformat) 2: -- ...
- 实用ExtJS教程100例-008:使用iframe填充ExtJS Window组件
上面两节中我们分别演示了ExtJS Window的常用功能 和 如何最小化ExtJS Window组件,在这篇内容中我们来演示一下如何使用iframe填充window组件. 思路很简单,首先创建一个w ...