Codeforces 551C GukiZ hates Boxes(二分)
Problem C. GukiZ hates Boxes
Solution:
假设最后一个非零的位置为K,所有位置上的和为S
那么答案的范围在[K+1,K+S].
二分这个答案ans,然后对每个人尽量在ans时间内搬最多的砖.可以得出至少需要多少个人才能搬完.这个可以在O(n)的时间内利用贪心得到
只要判断需要的人数是否小于等于实际的人数就好了
时间复杂度O(nlogS)
#include <bits/stdc++.h>
using namespace std; const int N = ;
int a[N];
int n, m, t;
long long s; inline bool check( long long x )
{
int k = m;
long long s = ;
for( int i = ; i <= t; ++i ) {
s += a[i];
while( s + i >= x ) {
s -= x - i;
if( --k < ) return ;
}
}
if(k==) return s<=;
return ;
} int main()
{
ios::sync_with_stdio( );
cin >> n >> m;
for( int i = ; i <= n; ++i ) {
cin >> a[i];
s += a[i];
if( a[i] != ) t = i;
}
long long l = t + , r = s + t,ans=-;
while( l <= r ) {
long long mid = ( l + r ) >> ;
if( check( mid ) ) r = mid - ,ans=mid;
else l = mid + ;
}
cout << r + << endl; }
Codeforces 551C GukiZ hates Boxes(二分)的更多相关文章
- 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( ...
- 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 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/ ...
- 【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个人,最開始都站在第一个箱子的左边, 每个人在每一秒钟都必须做出两种选 ...
- CF GukiZ hates Boxes 【二分+贪心】
Professor GukiZ is concerned about making his way to school, because massive piles of boxes are bloc ...
- Codeforces551 C. GukiZ hates Boxes
二分答案 + 贪心 传送门:$>here<$ $Solution$ 二分时间+贪心验证.思维难度主要在验证上,然而坑人的点却在n的取值上.那么先来谈如何验证.在已知时间的条件下,能否用一种 ...
随机推荐
- solrnet - document
Overview and basic usage Mapping Initialization Create/Update/Delete Querying Faceting Highlightin ...
- Win32中文件的操作
1 文件的创建或打开 HANDLE CreateFile( LPCTSTR lpFileName, //文件路径和名称 DWORD dwDesiredAccess, //访问方式,最常用的值 ...
- 【转】unity3d 各种优化综合
检测方式: 一,unity3d 渲染统计窗口 Game视窗的Stats去查看渲染统计的信息: 1.FPS fps其实就是 frames per second,也就是每一秒游戏执行的帧数,这个数值越 ...
- java基础(十三)常用类总结(三)
这里有我之前上课总结的一些知识点以及代码大部分是老师讲的笔记 个人认为是非常好的,,也是比较经典的内容,真诚的希望这些对于那些想学习的人有所帮助! 由于代码是分模块的上传非常的不便.也比较多,讲的也是 ...
- SQLyog之MySQL客户端的下载、安装和使用
本博文的主要内容有 .SQLyog的下载 .SQLyog的安装 .SQLyog的使用 1.SQLyog的下载 1.进入SQLyog官网, https://www.webyog.com/en 或 ...
- hdoj 4883 TIANKENG’s restaurant【贪心区间覆盖】
TIANKENG’s restaurant Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/O ...
- nyoj 32 组合数【简单dfs】
组合数 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 找出从自然数1.2.... .n(0<n<10)中任取r(0<r<=n)个数的所有组合 ...
- IE的Cookie目录和临时缓存目录的关系
1.IE的Cookie位置注册表设置: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folde ...
- BootStrap-table 客户端分页和服务端分页的区别
当服务器没有对数据进行分页时,前端页面设计又要求进行分页,要分开来设置. 服务端分页: responseHandler: function(data){ return data.response; } ...
- MySQL (DCL)
DCL语句 :数据库系统管理员使用,也就是数据库管理员 root 可以添加用户.删除用户.授予和限制用户权限,这些用户的信息可以在数据库的mysql数据库中查询到 1.查看用户信息 1.用ro ...