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次机会删除初始串的字符问最多操作几次后刚好凑不成目标 ...
随机推荐
- JOB+MERGE 跨服务器同步数据
为了解决单服务器压力,将库分服务器部署,但是原来用触发器实现的表数据同步就实现不了了. 因为总监老大不允许 开启分布式事务(MSDTC),我又不想为了一个几千行的基础数据做复制订阅. 于是乎决定用 J ...
- 算法设计手冊(第2版)读书笔记, Springer - The Algorithm Design Manual, 2ed Steven S.Skiena 2008
The Algorithm Design Manual, 2ed 跳转至: 导航. 搜索 Springer - The Algorithm Design Manual, 2ed Steven S.Sk ...
- H5单页面架构:自定义路由 + requirejs + zepto + underscore
angular优点: 强大的数据双向绑定 View界面层组件化 内置的强大服务(例如表单校验) 路由简单 angular缺点: 引入的js较大,对移动端来说有点吃不消 语法复杂,学习成本高 backb ...
- Unity NGUI 血条制作
NGUI 血条制作步骤 实现过程: 模拟血条的变化当点击按钮Button是血条会实时发生变化. 1.向Unity中导入NGUI2.6.3.unitypackage 点击create your ui 后 ...
- gcc和arm-linux-gcc区别
安装arm-linux-gcc的时候,查了不少资料,总算环境搭好了.于是,想写个程序员的经典程序---hello world. 语法都没错,生成test.c. 命令行运行:arm-linux-gcc ...
- NET基础课--组件2
强命名组件:使用sn.exe生成公钥私钥对,公钥可以用工具查看.snk文件需严格保护. sn -k d:\iron.snk 生成公钥私钥对 sn -p d:\iron.snk d:\ ...
- zepto的touch.js左右滑动存在一些问题,用百度的touch.js代替
这几天用zepto想写一个移动端的活动,在实现左右滑动触发动画时,发现zepto的touch.js在ios的微信上有问题. 问题描述:左右滑动时如果手指没有一直跟频幕贴着(在手机上滑动时,如果手指不是 ...
- transform的2D部分,嗯…就这个标题了。
上一次写了transition的内容,这次就写拼写很类似的另外一个属性transform好了……我英语差这件事就不要吐槽了,下面是正文,真的: transition是过渡,transform是变换. ...
- appium安装 For windows
java sdk,android SDK,maven,genymotion全部已经安装完毕,只是安装appium 因为现在的appium(AppiumForWindows_1_4_13_1)需要自己重 ...
- Json.Net序列化和反序列化设置
首先补充一点,Json.Net是支持序列化和反序列化DataTable,DataSet,Entity Framework和NHibernate的.我举例说明DataTable的序列化和反序列化.创建一 ...