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 ...
随机推荐
- STM32 Timer : Base Timer, Input Capture, PWM, Output Compare
http://www.cs.indiana.edu/~geobrown/book.pdf An example of a basic timer is illustrated in Figure 10 ...
- USBDM RS08/HCS08/HCS12/Coldfire V1,2,3,4/DSC/Kinetis Debugger and Programmer -- Driver Install
Installation of USBDM USB drivers for Windows There are four installers provided: USBDM_Drivers_x_x_ ...
- Snmp学习总结(二)——WinXP安装和配置SNMP
一.安装SNMP 今天讲解一下在XP下安装SNMP协议,安装步骤如下:
- Continuous Integration for iOS Apps with Visual Studio Team Services
原文引用自:https://blog.xamarin.com/continuous-integration-for-ios-apps-with-visual-studio-team-services/ ...
- 在ASP.NET MVC中实现登录后回到原先的界面
有这样的一个需求:提交表单,如果用户没有登录,就跳转到登录页,登录后,跳转到原先表单提交这个页面,而且需要保持提交表单界面的数据. 提交表单的页面是一个强类型视图页,如果不考虑需要保持提交表单界面的数 ...
- RenderPartial和RenderAction区别
本篇参考了Shailendra Chauhan和 Jag Reehal的博文. RenderParital和RenderAction的共同点: ※ 都能返回部分视图 ※ 返回的部分视图和主视图共用一个 ...
- DirectX - dds图片格式(DDSURFACEDESC2)
DDS是DirectDraw Surface的缩写,它是DirectX纹理压缩(DirectX Texture Compression,简称DXTC)的产物. DXTC减少了纹理内存消耗的50%甚至更 ...
- how to use fiddler and wireshark to decrypt ssl
原文地址: http://security14.blogspot.jp/2010/07/how-to-use-fiddler-and-wireshark-to.html Requirements2 C ...
- ios7下UISearchBar UITextField 光标不出现的问题
app支持ios7,在UINavBar 里面加入搜索框,结果光标一直出现不了.在overstackflow网站搜索了一下,竟然有人遇到相同的问题.... 解决办法如下: searchBar.tintC ...
- XMLHttpRequest 的使用······
// JavaScript Document /*创建XMLHttpRequest对象 *这段代码的核心分为三步: 1.建立一个变量 xmlHttp 来引用即将创建的 XMLHttpRequest 对 ...