传送门:>Here<

$n$个位置上各放着$a_i$个箱子。有$m$个人位于初始位于下标0,每人每秒可以选择在当前位置上搬走一个箱子(即让一个箱子消失),或向前走一步。多个人可以同时位于一个位置。问最少几秒能搬完所有箱子。

$Solution$

二分时间+贪心验证。思维难度主要在验证上,想要最优就是让每一秒都不浪费。不浪费就是指:不傻站在哪儿,不跟别人抢一个箱子。如此我们每一个人单独考虑即可。这有点让我想到了那道很经典的“蚂蚁”,每个人都一样,其工作是可以等效的。

$Code$

long long

  1. /*By QiXingzhi*/
  2. #include <cstdio>
  3. #include <queue>
  4. #include <cstring>
  5. #include <algorithm>
  6. #define r read()
  7. #define Max(a,b) (((a)>(b)) ? (a) : (b))
  8. #define Min(a,b) (((a)<(b)) ? (a) : (b))
  9. using namespace std;
  10. typedef long long ll;
  11. #define int ll
  12. const int N = ;
  13. const int INF = ;
  14. inline int read(){
  15. int x = ; int w = ; register int c = getchar();
  16. while(c ^ '-' && (c < '' || c > '')) c = getchar();
  17. if(c == '-') w = -, c = getchar();
  18. while(c >= '' && c <= '') x = (x << ) +(x << ) + c - '', c = getchar();
  19. return x * w;
  20. }
  21. int a[N],b[N];
  22. int n,m,L,R,Mid,tot,ans,lim;
  23. inline bool judge(int x){
  24. int num = ;
  25. int res = ;
  26. for(int pile = ; pile <= lim; ++pile){
  27. res += a[pile];
  28. while(res + pile >= x){
  29. res -= x - pile;
  30. ++num;
  31. if(num > m) return ;
  32. }
  33. }
  34. if(num == m){
  35. return res <= ;
  36. }
  37. return ;
  38. }
  39. #undef int
  40. int main(){
  41. #define int ll
  42. // freopen(".in","r",stdin);
  43. n = r, m = r;
  44. for(int i = ; i <= n; ++i){
  45. a[i] = r;
  46. tot += a[i];
  47. if(a[i] != ) lim = i;
  48. }
  49. L = + lim, R = lim + tot;
  50. ans = -;
  51. while(L <= R){
  52. Mid = (L + R) / ;
  53. if(judge(Mid)){
  54. ans = Mid;
  55. R = Mid - ;
  56. }
  57. else{
  58. L = Mid + ;
  59. }
  60. }
  61. printf("%lld",ans);
  62. return ;
  63. }

Codeforces551 C. GukiZ hates Boxes的更多相关文章

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

  2. Codeforces 551C GukiZ hates Boxes(二分)

    Problem C. GukiZ hates Boxes Solution: 假设最后一个非零的位置为K,所有位置上的和为S 那么答案的范围在[K+1,K+S]. 二分这个答案ans,然后对每个人尽量 ...

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

  4. codeforces 551 C GukiZ hates Boxes

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. 微软Azure AspNetCore微服务实战第1期【补充2017-09-09活动】

    2017年09月09日,冒着酷暑,我们在(上海徐汇)虹桥路3号港汇中心2座10层组织了一次微软Azure AspNetCore微服务实战活动. 由于前期工作繁忙,活动完成之后,没能及时发布相关信息,特 ...

  2. 五子棋(无AI winform gdi+)

    之前无意间在博客园看到一篇用深度学习玩马里奥的文章,于是就想做这个小东西来测试人工智能算法(准备用PYTHON的库,对神经网络的梦已经做了好多年了,但是太难了,一直懒得动它),本来是想用WPF做UI, ...

  3. python读取/创建XML文件

    Python中定义了很多处理XML的函数,如xml.dom,它会在处理文件之前,将根据xml文件构建的树状数据存在内存.还有xml.sax,它实现了SAX API,这个模块牺牲了便捷性,换取了速度和减 ...

  4. Joyride (spaf)

    题目链接:https://codeforces.com/gym/101873/problem/C spaf的复杂度有点迷,按道理来说,一个简单的spaf在这题的复杂度是1e9,所以不敢写,然后用优先队 ...

  5. rabbitmq集群运维一点总结

    说明:以下操作都以三节点集群为例,机器名标记为机器A.机器B.机器C,如果为双节点忽略机器C,如果为各多节点则与机器C操作相同 一.rabbitmq集群必要条件 1.1.绑定实体ip,即ip a所能查 ...

  6. AtCoder Beginner Contest 049 & ARC065 連結 / Connectivity AtCoder - 2159 (并查集)

    Problem Statement There are N cities. There are also K roads and L railways, extending between the c ...

  7. Codeforces Round #534 (Div. 2)D. Game with modulo-1104-D(交互+二分+构造)

    D. Game with modulo time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. JMeter压测分布式部署

    监控JMeter压力机的性能

  9. Angular 自定义过滤器

    <!DOCTYPE html><html ng-app="myApp"><head lang="en"> <meta ...

  10. ELK日志系统+x-pack安全验证

    根据之前已经搭好的ELK系统,现在加一个x-pack插件上去,不然谁拿到ip和端口都可以访问elasticsearch和kibana. 要的效果如下:打开kibana界面的时候要让其输入用户名密码才能 ...