ZJOI2007仓库建设
来源:互联网 发布:人依赖网络例子 编辑:程序博客网 时间:2024/06/07 20:48
斜率优化
# include <stdio.h># include <stdlib.h># include <iostream># include <string.h># include <algorithm># define IL inline# define RG register# define Fill(a, b) memset(a, b, sizeof(a))using namespace std;typedef long long ll;IL ll Read(){ RG char c = getchar(); RG ll x = 0, z = 1; for(; c > '9' || c < '0'; c = getchar()) z = c == '-' ? -1 : 1;; for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + c - '0'; return x * z;}const int MAXN(1000010);const ll INF(1e18);int n, cnt, Q[MAXN], tail, head;ll f[MAXN], c[MAXN], p[MAXN], x[MAXN], s[MAXN], g[MAXN];IL double Calc(RG int i, RG int j){ return 1.0 * (f[i] + g[i] - f[j] - g[j]) / (p[i] - p[j]);}int main(){ n = Read(); for(RG int i = 1; i <= n; i++){ x[i] = Read(); p[i] = Read(); c[i] = Read(); p[i] += p[i - 1]; s[i] = s[i - 1] + p[i - 1] * (x[i] - x[i - 1]); g[i] = x[i] * p[i] - s[i]; } for(RG int i = 1; i <= n; i++){ while(head < tail && Calc(Q[head], Q[head + 1]) <= x[i]) head++; f[i] = f[Q[head]] + c[i] + s[i] + g[Q[head]] - x[i] * p[Q[head]]; while(head < tail && Calc(Q[tail - 1], Q[tail]) > Calc(Q[tail], i)) tail--; Q[++tail] = i; } printf("%lld\n", f[n]); return 0;}
阅读全文
0 0
- 【ZJOI2007】仓库建设
- BZOJ [ZJOI2007]仓库建设
- 1096: [ZJOI2007]仓库建设
- bzoj1096: [ZJOI2007]仓库建设
- [BZOJ1096][ZJOI2007]仓库建设
- 1096: [ZJOI2007]仓库建设
- 1096: [ZJOI2007]仓库建设
- [BZOJ1096] [ZJOI2007]仓库建设
- 1096: [ZJOI2007]仓库建设
- bzoj1096【ZJOI2007】仓库建设
- 【bzoj1096】[ZJOI2007]仓库建设
- BZOJ1096 [ZJOI2007] 仓库建设
- BZOJ1096 ZJOI2007 仓库建设
- 1096: [ZJOI2007]仓库建设
- [ZJOI2007] 仓库建设
- BZOJ1096: [ZJOI2007]仓库建设
- bzoj1096: [ZJOI2007]仓库建设
- [BZOJ1096][ZJOI2007]仓库建设
- USACO08MAR Land Acquisition
- 关于linux系统中无法识别某一命令问题的解决方案
- Spring的简单实现实例(Spring的java配置方式)
- EasyDemo* ImageView及其子类体系结构图(on Github)
- Guitar Pro 7 注册机-注册码地址汇总
- ZJOI2007仓库建设
- 关于FTP主动模式与被动模式的一点理解
- 省选专练SCOI2007修车
- 简易波形显示器——单片机实验结课成果
- html 提交表单,但不跳转页面处理返回值
- CTF练习平台sql注入测试writeup
- [CSAPP]计算机系统漫游
- Matlab如何打包成jar并给java使用(混合编程)
- 基于Tensorflow的android手写数字识别