Codeforces 551C GukiZ hates Boxes 二分答案
题意:
1 0 2
思路:
二分答案,设答案为x。即须要x秒来搬完石头
先让这个学生走到尽头
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <cstdio>
#include <map>
#include <queue>
#include <algorithm>
#include <stack>
#include <cstring>
#include <cmath>
#include <set>
#include <vector>
using namespace std;
template <class T>
inline bool rd(T &ret) {
char c; int sgn;
if (c = getchar(), c == EOF) return 0;
while (c != '-' && (c<'0' || c>'9')) c = getchar();
sgn = (c == '-') ? -1 : 1;
ret = (c == '-') ? 0 : (c - '0');
while (c = getchar(), c >= '0'&&c <= '9') ret = ret * 10 + (c - '0');
ret *= sgn;
return 1;
}
template <class T>
inline void pt(T x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (x > 9) pt(x / 10);
putchar(x % 10 + '0');
}
typedef long long ll;
typedef pair<ll, ll> pii;
const int inf = 1e9;
const int N = 1e5 + 10;
int n, m;
int a[N], b[N];
bool ok(ll x) {
for (int i = 1; i <= n; i++)b[i] = a[i];
int top = n, tmp = m;
while (tmp-->0 && top) {
ll lef = x - top;
while (lef && top) {
if (b[top] == 0) { top--;continue; }
if (b[top] <= lef) {
lef -= b[top--];
}
else { b[top] -= (int)lef;lef = 0; }
}
}
while (top && b[top] == 0)top--;//找到最后一个而且不是0的点
return top == 0;
}
int main() {
rd(n); rd(m);
int d = 1;
for (int i = 1; i <= n; i++) {
rd(a[i]);
}
while (a[n] == 0)n--; //把最后的0删掉
ll l = 1, r = 1e15, ans;
while (l <= r) {
ll mid = (l + r) >> 1;
if (ok(mid)) {
ans = mid;
r = mid - 1;
}
else l = mid + 1;
}
pt(ans);
return 0;
}
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堆石头排成一列,每堆有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 ...
- CodeForces 779D. String Game(二分答案)
题目链接:http://codeforces.com/problemset/problem/779/D 题意:有两个字符串一个初始串一个目标串,有t次机会删除初始串的字符问最多操作几次后刚好凑不成目标 ...
随机推荐
- RIAidea – Focus on Flash/Flex/AIR » About Me
RIAidea – Focus on Flash/Flex/AIR » About Me Browse > Home > About Me Tuesday, May 20, 2014 | ...
- IOS 网络判断
Reachability *connectionNetWork= [Reachability reachabilityForInternetConnection] ; int status = [co ...
- WINDOWS 下搭建 OC 集成开发环境
Objective-C是苹果软件的编程语言,想要上机学习.调试,有一个集成开发环境(IDE)方便很多.有三类方法搭建Objective-C的集成开发环境: 1) 使用苹果的平台,集成开发环境使用X ...
- 浅谈ThreadPool 线程池
本文来自:http://www.cnblogs.com/xugang/archive/2010/04/20/1716042.html 相关概念: 线程池可以看做容纳线程的容器: 一个应用程序最多只能有 ...
- 并查集+二分-hdu-4750-Count The Pairs
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4750 题目大意: 给一无向图,n个点,m条边,每条边有个长度,且不一样.定义f(i,j)表示从节点i ...
- 克隆虚拟机,如何将克隆虚拟的网卡设置为eth0
1.先删掉/etc/udev/rules.d/70-persistent-net.rules文件里的eth0,并要记住eth1的那个网卡的mac地址等下要用.2.把那个eth1修改为eth03.编辑网 ...
- drupal 7.23 上传中文命名文件bug
$file->filename = trim(drupal_basename($_FILES['files']['name'][$source]), '.'); //在此行下 添加以下代码即可( ...
- 登陆权限验证Session和Cookie用法及BasePage类使用
最近在做ASP.NET的项目时,接触到了登陆权限模块,所有总结了一下登陆时用到的知识和方法技巧. 如图说明:实现的效果如图,由于验证码验证比较简单这里就不介绍了 首先用代码生成器生成项目,以三层为例进 ...
- SQL语句函数详解__sql聚合函数
函数是一种有零个或多个参数并且有一个返回值的程序.在SQL中Oracle内建了一系列函数,这些函数都可被称为SQL或PL/SQL语句,函数主要分为两大类:单行函数.组函数 本文将讨论如何使用单行函数及 ...
- Linux命令记录。
引用:http://www.cnblogs.com/xiaoluo501395377/archive/2013/03/31/2992500.html 首先,需要确定的是知道的是:对于Linux系统来说 ...