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次机会删除初始串的字符问最多操作几次后刚好凑不成目标 ...
随机推荐
- AIX5.3CPU占用高的问题核查
AIX5.3 CPU占用高问题核查步骤 1.topas查看占用cpu占用最高的进程的PID 2.执行: ps -mp PID -o THREAD 以查找相应进程下所有正在占用 CPU 的线程的TID ...
- Old Sorting(转化成单调序列的最小次数,置换群思想)
Old Sorting Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit S ...
- Trie树|字典树(字符串排序)
有时,我们会碰到对字符串的排序,若采用一些经典的排序算法,则时间复杂度一般为O(n*lgn),但若采用Trie树,则时间复杂度仅为O(n). Trie树又名字典树,从字面意思即可理解,这种树的结构像英 ...
- java值传递
Java使用按值传递的函数调用方式,这往往使我感到迷惑.因为在基础数据类型和对象的传递上,我就会纠结于到底是按值传递,还是按引用传递.其实经过学习,Java在任何地方,都一直发挥着按值传递的本色. 首 ...
- Ffplay视频播放流程
主框架流程 下图是一个使用“gcc+eygpt+graphviz+手工调整”生成的一个ffplay函数基本调用关系图,其中只保留了视频部分,去除了音频处理.字幕处理以及一些细节处理部分. 注:图中的数 ...
- 远程调试weinre的使用
一.用途 *鉴于在浏览器调试移动端页面无法准确反映移动端实际情况并无法高效调试,故常常使用远程调试工具通过电脑连接手机进行调试,常用远程调试方式: 1.chrome连接安卓机远程调试 2.Mac连接苹 ...
- session之退出登陆
<span style="font-size:32px;">//使用SESSION必须先开启session session_start(); //彻底删除session ...
- 终极解法According to TLD or attribute directive in tag file, attribute select does not accept any expressions
3天硬是是把这个问题解决了 有时候突然上个厕所灵感就来了 第一次向用JSTL解析xml 然后我想遍历整个xml文档打印出来 居然不让我输入变量 那让我怎么办啊 在网上各种找答案 说什么<%@ t ...
- sql server的两个类型转换函数
今天遇到一个sql的问题,条件中有个去当前月第一天(2013-8-23 0:00:00),很简单CAST(DATEADD(dd,-DAY(GETDATE())+1,GETDATE()) AS DATE ...
- php Debugging with Xdebug and Sublime Text 3(转)
Debugging – we all do it a lot. Writing code perfectly the first time around is hard and only a few ...