二分+贪心 || CodeForces 551C GukiZ hates Boxes
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
#define SZ 100005
#define INF 1e15+10
long long a[SZ], b[SZ];
int n, m;
int check(long long x)
{
int flag = ;
long long p = , t;//时间x
for(int i = ; i <= n; i++) b[i] = a[i];
for(int i = ; i <= m; i++)
{
t = x - p;
while(t > && p <= n)
{
if(t > b[p]) {t -= b[p]; b[p] = ; p++; t--;}
//do{p++; t--;} while(b[p] == 0);
else if(t == b[p]) {b[p] = ; p++; t = ;}
else {b[p] -= t; t = ;}
}
}
for(int i = ; i <= n; i++)
if(b[i] > ) flag = ;
if(!flag) return ;
return ;
}
int main()
{
scanf("%d %d", &n, &m);
for(int i = ; i <= n; i++)
scanf("%lld", &a[i]);
long long l = , r = INF, mid;
while(r > l)
{
mid = (r + l) / ;
if(check(mid)) r = mid;
else l = mid + ;
}
printf("%lld\n", r);
return ;
}
二分+贪心 || CodeForces 551C GukiZ hates Boxes的更多相关文章
- Codeforces 551C GukiZ hates Boxes(二分)
Problem C. GukiZ hates Boxes Solution: 假设最后一个非零的位置为K,所有位置上的和为S 那么答案的范围在[K+1,K+S]. 二分这个答案ans,然后对每个人尽量 ...
- 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 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 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 ...
- CF GukiZ hates Boxes 【二分+贪心】
Professor GukiZ is concerned about making his way to school, because massive piles of boxes are bloc ...
- 【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个人,最開始都站在第一个箱子的左边, 每个人在每一秒钟都必须做出两种选 ...
- Codeforces551 C. GukiZ hates Boxes
二分答案 + 贪心 传送门:$>here<$ $Solution$ 二分时间+贪心验证.思维难度主要在验证上,然而坑人的点却在n的取值上.那么先来谈如何验证.在已知时间的条件下,能否用一种 ...
随机推荐
- Android6.0 危险权限和普通权限
Normal Permissions如下 ACCESS_LOCATION_EXTRA_COMMANDS ACCESS_NETWORK_STATE ACCESS_NOTIFICATION_POLICY ...
- 51nod1127【尺取】
思路: 尺取,写挫了,debug了半天. #include <bits/stdc++.h> using namespace std; typedef long long LL; const ...
- PTA 朋友圈【并查集的合并问题】
一开始,考虑的是每次就是把第一个作为祖先,这样很明显是错误的,比如 7 4 3 1 2 3 2 4 2 3 5 6 7 1 6 所以这正是更好地体现对于集合的代表.只有把所有的元素合并一下,然后选一个 ...
- Educational Codeforces Round 12 A. Buses Between Cities
题意: 从A到B的汽车每隔 a 分钟发车一次,从A到B要ta分钟. 从B到A汽车每隔b分钟发车一次,从B到A要ta分钟. Simion从A出发,问他在A->B的途中共遇到了多少辆车. 汽车都是从 ...
- Hdu 5446 Unknown Treasure (2015 ACM/ICPC Asia Regional Changchun Online Lucas定理 + 中国剩余定理)
题目链接: Hdu 5446 Unknown Treasure 题目描述: 就是有n个苹果,要选出来m个,问有多少种选法?还有k个素数,p1,p2,p3,...pk,结果对lcm(p1,p2,p3.. ...
- 模拟 Codeforces Round #297 (Div. 2) A. Vitaliy and Pie
题目传送门 /* 模拟:这就是一道模拟水题,看到标签是贪心,还以为错了呢 题目倒是很长:) */ #include <cstdio> #include <algorithm> ...
- Mysql读写分离操作之mysql-proxy
常见的读写方式 基于程序代码内部实现 在代码中根据select.insert进行选择分类:这类方法也是生产常用的,效率最高,但是对开发人员比较麻烦.架构不能灵活调整 基于中间件的读写分离: mysql ...
- 单机版solr6.3和分布式solr6.3的安装部署
一.单机版的solr部署 我的是在windows下安装的,linux同理 1. 安装JDK8,并配置好环境变量,一般我们经常开发的电脑上应该都有JDk了,所以这一步可以忽略. 2. 解压solr6.3 ...
- 机器学习概念之特征选择(Feature selection)
不多说,直接上干货! .
- JS防止页面被其他网站iframe使用方法
if(window.top !== window.self){ window.top.location = window.location;} 这句话的意识是说:如果当前窗体不是顶级窗体,就把自己变成 ...