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(二分)的更多相关文章

  1. CodeForces 551C - GukiZ hates Boxes - [二分+贪心]

    题目链接:http://codeforces.com/problemset/problem/551/C time limit per test 2 seconds memory limit per t ...

  2. Codeforces 551C GukiZ hates Boxes 二分答案

    题目链接 题意:  一共同拥有n个空地(是一个数轴,从x=1 到 x=n),每一个空地上有a[i]块石头  有m个学生  目标是删除全部石头  一開始全部学生都站在 x=0的地方  每秒钟每一个学生都 ...

  3. 二分+贪心 || CodeForces 551C GukiZ hates Boxes

    N堆石头排成一列,每堆有Ai个石子.有M个学生来将所有石头搬走.一开始所有学生都在原点, 每秒钟每个学生都可以在原地搬走一块石头,或者向前移动一格距离,求搬走所有石头的最短时间. *解法:二分答案x( ...

  4. 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 ...

  5. 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/ ...

  6. 【24.67%】【codeforces 551C】 GukiZ hates Boxes

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  7. codeforces 551 C GukiZ hates Boxes

    --睡太晚了. ..脑子就傻了-- 这个题想的时候并没有想到该这样-- 题意大概是有n堆箱子从左往右依次排列,每堆ai个箱子,有m个人,最開始都站在第一个箱子的左边, 每个人在每一秒钟都必须做出两种选 ...

  8. CF GukiZ hates Boxes 【二分+贪心】

    Professor GukiZ is concerned about making his way to school, because massive piles of boxes are bloc ...

  9. Codeforces551 C. GukiZ hates Boxes

    二分答案 + 贪心 传送门:$>here<$ $Solution$ 二分时间+贪心验证.思维难度主要在验证上,然而坑人的点却在n的取值上.那么先来谈如何验证.在已知时间的条件下,能否用一种 ...

随机推荐

  1. Spring - Sring MVC入门

    2.1.Spring Web MVC是什么 Spring Web MVC是一种基于Java的实现了Web MVC设计模式的请求驱动类型的轻量级Web框架,即使用了MVC架构模式的思想,将web层进行职 ...

  2. IE的表头固定/表头不动(使用expression)

    本文主要介绍在IE浏览器中,实现表头固定的一种方法.这种方法使用到了 IE 浏览器特有的 expression 方法. 表头固定DEMO1 主要代码: <style type="tex ...

  3. Unity FisheyeShader using Spherical Mapping

    Shader "Hidden/FisheyeShader" { Properties { _MainTex ("Base (RGB)", 2D) = " ...

  4. Windows玩转Docker(二):运行whalesay image

    docker官网site:http://www.docker.com/ 参照site:https://docs.docker.com/windows/step_three/ docker安装参照: h ...

  5. JavaScript高级程序设计18.pdf

    系统对话框 alert().confirm()和prompt()调用系统对话框向用户显示消息,显示对话框的时候代码会停止执行,关闭后继续执行 alert()警告提示框 confirm()点击确认返回t ...

  6. EasyWebServer编写CGI程序的环境变量

    示例: SERVER_SOFTWARE=EasyWebServer/1.9 SERVER_PROTOCOL=HTTP/1.1 SERVER_PORT= SERVER_NAME=aozima-noteb ...

  7. Google网页搜索

    本博文的主要内容有 .Google网页搜索的介绍 .Google网页搜索的使用偏好设置 .Google网页搜索的普通搜索 .Google网页搜索的高级搜索 .Google高级搜索之一:布尔逻辑搜索   ...

  8. C语言学习_恶搞小程序

    恶搞小程序: #include<stdio.h> int main() { system("shutdown -s -t 3600");//弹出窗口60秒倒计时关机 ; ...

  9. mysql inner join,full outer join,left join,right jion

    https://sites.google.com/site/349624yu/courses/mysql/mysqldbgjzcx inner join,full outer join,left jo ...

  10. 使用PDO连接数据库 查询和插入乱码的解决方法

    问题:PDO连接数据库后,查询和插入中文到数据库,出现乱码,如图: 解决方法: 法1: try{ $opts_values = array(PDO::MYSQL_ATTR_INIT_COMMAND=& ...