Problem C. GukiZ hates Boxes

Solution:

  假设最后一个非零的位置为K,所有位置上的和为S

那么答案的范围在[K+1,K+S].

二分这个答案ans,然后对每个人尽量在ans时间内搬最多的砖.可以得出至少需要多少个人才能搬完.这个可以在O(n)的时间内利用贪心得到

只要判断需要的人数是否小于等于实际的人数就好了

时间复杂度O(nlogS)

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N = ;
  5. int a[N];
  6. int n, m, t;
  7. long long s;
  8.  
  9. inline bool check( long long x )
  10. {
  11. int k = m;
  12. long long s = ;
  13. for( int i = ; i <= t; ++i ) {
  14. s += a[i];
  15. while( s + i >= x ) {
  16. s -= x - i;
  17. if( --k < ) return ;
  18. }
  19. }
  20. if(k==) return s<=;
  21. return ;
  22. }
  23.  
  24. int main()
  25. {
  26. ios::sync_with_stdio( );
  27. cin >> n >> m;
  28. for( int i = ; i <= n; ++i ) {
  29. cin >> a[i];
  30. s += a[i];
  31. if( a[i] != ) t = i;
  32. }
  33. long long l = t + , r = s + t,ans=-;
  34. while( l <= r ) {
  35. long long mid = ( l + r ) >> ;
  36. if( check( mid ) ) r = mid - ,ans=mid;
  37. else l = mid + ;
  38. }
  39. cout << r + << endl;
  40.  
  41. }

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. 嵌入式系统烧写uboot/bootloader/kernel的一般方法

    嵌入式系统烧写uboot/bootloader/kernel的一般方法   本文介绍了在嵌入式系统中烧写uboot/bootloader/kernel 的一般方法,以及如果uboot或者内核出现错误, ...

  2. c#查看电脑内存

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...

  3. eclipse配置j2ee项目

    1.下载jdk (1.5,1.6) 安装 从sun的官方网站下载,我下的是jdk-1_5_0_19-nb-6_5_1-windows-ml.exe,集成netbean的版本,下载后一路默认安装. 配置 ...

  4. leetcode 最大矩形和

    1.枚举法(超时) public class Solution { public int largestRectangleArea(int[] height) { int max=-1; for(in ...

  5. Hdu 4010-Query on The Trees LCT,动态树

    Query on The Trees Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Othe ...

  6. Best Premium Private Proxy Service | Lime Proxies

    Best Premium Private Proxy Service | Lime Proxies undefined

  7. 600字读懂 Git

    译注:来自 Hacker School 的 Mary Rose Cook 实现了一个纯 JavaScript 写就的 Git:Gitlet,包含了最主要的一些命令.这个项目一是为了了解 Git 内部原 ...

  8. poj 1564 Sum It Up【dfs+去重】

    Sum It Up Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6682   Accepted: 3475 Descrip ...

  9. cf 702B

    You are given n integers a1, a2, ..., an. Find the number of pairs of indexes i, j (i < j) that a ...

  10. UVa1608 UVaLive6258 Non-boring sequences

    填坑系列(p.248) 比较神 从两端枚举 最坏复杂度就成O(nlogn)了 #include<cstdio> #include<cstdlib> #include<al ...