Codeforces 1137E 凸包
题意:有一辆火车,初始只有一个车厢,权值为0。有3种操作:
1:在火车头前面加若干辆车
2:在火车车尾加若干辆车
3:每个车的权值加上b + (i - 1) * s,其中i是指这节车厢是从头算的第几个车厢。
每次操作后,询问离火车头最近的权值最小的车厢。
思路:看这篇博客就行了,实现方式比较巧妙。
代码:
#include <bits/stdc++.h>
#define db long long
#define LL long long
using namespace std;
const int maxn = 500010;
const double eps = 1e-9;
int top;
LL b[maxn], s[maxn];
struct point {
db x, y;
point(){};
point(db _x, double _y) :x(_x), y(_y){};
};
point st[maxn];
int n;
LL cal(point x, int now) {
return b[now] - b[x.y] + (x.x - 1) * (s[now] - s[x.y]);
}
LL mul(LL x, LL y, LL x1, LL y1) {
return x * y1 - x1 * y;
}
void add(LL x, LL y) {//x 实际位置 y 读入次序
if(cal(st[top], y) == 0) return;
LL tmp = cal(point(x, y), y);
while(top >= 2) {
if(mul(st[top].x - st[top - 1].x, cal(st[top], y) - cal(st[top - 1], y), x - st[top].x, tmp - cal(st[top], y)) > 0) break;
top--;
}
st[++top] = point(x, y);
}
void del(int x) {
while(top >= 2 && cal(st[top], x) >= cal(st[top - 1], x))
top--;
}
int main() {
int n, m, op;
LL x, y;
scanf("%d%d", &n, &m);
st[++top] = point(1, 0);
for (int i = 1; i <= m; i++) {
b[i] = b[i - 1];
s[i] = s[i - 1];
scanf("%d", &op);
if(op == 1) {
scanf("%lld", &x);
b[i] = s[i] = 0;
st[top = 1] = point(1, i);
n += x;
} else if(op == 2) {
scanf("%lld", &x);
add(n + 1, i);
n += x;
} else {
scanf("%lld%lld", &x, &y);
b[i] += x;
s[i] += y;
del(i);
}
printf("%lld %lld\n", st[top].x, cal(st[top], i));
}
}
Codeforces 1137E 凸包的更多相关文章
- CodeForces - 605C 凸包+直线与凸包判交
题目大意: 要完成两种属性p,q的需求,给定n个双属性物品及其单位个物品中含有的属性,要求选择最少的物品来达成属性需求.(可以选择实数个物品) 题解: 实际上是一种属性混合问题 我们知道对于两种双属性 ...
- codeforces 70D Professor's task(动态二维凸包)
题目链接:http://codeforces.com/contest/70/problem/D Once a walrus professor Plato asked his programming ...
- [置顶] Codeforces 70D 动态凸包 (极角排序 or 水平序)
题目链接:http://codeforces.com/problemset/problem/70/D 本题关键:在log(n)的复杂度内判断点在凸包 或 把点插入凸包 判断:平衡树log(n)内选出点 ...
- codeforces 70 D. Professor's task 动态凸包
地址:http://codeforces.com/problemset/problem/70/D 题目: D. Professor's task time limit per test 1 secon ...
- [codeforces/gym/101350/L]维护“凸包”
题目链接:http://codeforces.com/gym/101350/problems 给定n个墙,每个墙有一个高度,要支持动态修改墙的高度和查询这个“容器”能盛多少水. (队友)观察发现,能盛 ...
- Codeforces Round #549 (Div. 2) F 数形结合 + 凸包(新坑)
https://codeforces.com/contest/1143/problem/F 题意 有n条形如\(y=x^2+bx+c\)的抛物线,问有多少条抛物线上方没有其他抛物线的交点 题解 \(y ...
- Codeforces 166B - Polygon (判断凸包位置关系)
Codeforces Round #113 (Div. 2) 题目链接:Polygons You've got another geometrical task. You are given two ...
- CodeForces 166B (凸包)
求一个多边形是否完全在另一个凸多边形内. 乍一看,好像要判点在多边形内,但复杂度不允许,仔细一想,可以把两个多边形的点混起来求一个共同的凸包,如果共同的凸包依旧是原来凸包上的点,说明是. #inclu ...
- Codeforces Gym 100286A. Aerodynamics 计算几何 求二维凸包面积
Problem A. AerodynamicsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/co ...
随机推荐
- 9.9 Python 文档字符串
9.9 Python 文档字符串. 进入 Python 标准库所在的目录. 检查每个 .py 文件看是否有__doc__ 字符串, 如果有, 对其格式进行适当的整理归类. 你的程序执行完毕后, 应该会 ...
- HDU - 6116:路径计数 (组合数&NTT)
一个包含四个点的完全图,可以在任意节点出发,可以在任意节点结束,给出每个点被经过的次数,求有多少种合法的遍历序列.如果两个序列至少有一位是不同的,则认为它们不相同. Input 2 3 3 3 Sam ...
- Python之contextlib库及源码分析
Utilities for with-statement contexts __all__ = ["contextmanager", "closing", &q ...
- Java中取整和四舍五入
import java.math.BigDecimal; import java.text.DecimalFormat; public class TestGetInt{ public stati ...
- 【LIUNX】目录或文件权限,权限授予
三个三个一组看: 1. 第一段表示文件所有者对此文件的操作权限 2. 第二段表示文件所有者所在组对些文件的操作权限 3. 第三段表示除上述两种外的任何用户/组对此文件的操作权限 r读取:4 w写入:2 ...
- 利用git bash和git gui向git远程仓库提交文件
1.首先在该文件夹下git init 2.然后在github下面创建一个新仓库去存储你的代码 3.然后利用add添加远程仓库 4.然后点击stage changed 5.最后点击长传 参考链接:htt ...
- python 的日志logging模块
1.简单的将日志打印到屏幕 import logging logging.debug('This is debug message')logging.info('This is info messag ...
- Web缓存技术
本章导读 缓存主要是为了提高数据的读取速度.因为服务器和应用客户端之间存在着流量的瓶颈,所以读取大容量数据时,使用缓存来直接为客户端服务,可以减少客户端与服务器端的数据交互,从而大大提高程序的性能. ...
- composer 详解
composer 详解 http://blog.csdn.net/panpan639944806/article/details/16808261 https://www.phpcomposer.co ...
- erlang配置三方库
暴力的: 直接下载解压以后放到erlang的lib目录,比如/usr/local/Cellar/erlang/17.3/lib/erlang/lib 和谐的: 在用户名下建立.erlang文件 在里面 ...