bzoj1096题解
【解题思路】
预处理spi=∑pj(j∈[1,i]),si=si-1+(xi-xi-1)*spi-1表示把工厂1~i-1的产品都运到工厂i的花费。于是把工厂j+1~i的产品都运到工厂i的花费为si-sj-spj*(xi-xj)。
于是易得转移方程:f[i]=min{f[j]+s[i]-s[j]-sp[j]*(x[i]-x[j])+c[i]},转移成同的形式:((f[j]-s[j]+sp[j]*x[j])-(f[k]-s[k]+sp[k]*x[k]))/(sp[j]-sp[k])<x[i]。
因为较优转移方式为min,所以维护一个下凸壳即可。听说题目并没有保证x升序?(可能是我星际)所以假装要先排下序,复杂度O(nlog2n)。
【参考代码】
#include <algorithm>
#define range(i,low,high) for(register int i=(low);i<(high);++i)
#define dange(i,high,low) for(register int i=(high);i>(low);--i)
#define __function__(type) __attribute__((optimize("-O2"))) inline type
#define __procedure__ __attribute__((optimize("-O2"))) inline void
using namespace std; //quick_io {
#include <cctype>
#include <cstdio> __function__(long long) getint()
{
char c=getchar(); for(;!isdigit(c)&&c!='-';c=getchar());
short s=; for(;c=='-';c=getchar()) s*=-; long long r=;
for(;isdigit(c);c=getchar()) r=(r<<)+(r<<)+c-''; return r*s;
}
//} quick_io struct node
{
long long x,p,c;
__procedure__ input() {x=getint(),p=getint(),c=getint();}
__function__(bool) operator<(const node&t)const{return x<t.x;}
}factory[]; int q[]; long long s[]={},sp[]={},f[]; __function__(long long) getDP(const int&i,const int&j)
{
return f[j]+s[i]-s[j]-sp[j]*(factory[i].x-factory[j].x)+factory[i].c;
}
__function__(long long) getUP(const int&j,const int&k)
{
return f[j]-f[k]-s[j]+s[k]+sp[j]*factory[j].x-sp[k]*factory[k].x;
}
__function__(long long) getDOWN(const int&j,const int&k)
{
return sp[j]-sp[k];
} int main()
{
int n=getint(); range(i,,n+) factory[i].input();
range(i,,n+)
{
s[i]=s[i-]+(factory[i].x-factory[i-].x)*sp[i-];
sp[i]=sp[i-]+factory[i].p;
}
int head=,tail=; sort(factory+,factory+n+),f[]=;
range(i,,n+)
{
for(;head+<tail&&
getUP(q[head+],q[head])<factory[i].x*getDOWN(q[head+],q[head]);
++head
);
f[i]=getDP(i,q[head]);
for(;head+<tail&&
getUP(i,q[tail-])*getDOWN(q[tail-],q[tail-])<
getUP(q[tail-],q[tail-])*getDOWN(i,q[tail-]);
--tail
);
q[tail++]=i;
}
return printf("%lld\n",f[n]),;
}
bzoj1096题解的更多相关文章
- BZOJ1096:[ZJOI2007]仓库建设——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=1096 L公司有N个工厂,由高到底分布在一座山上.如图所示,工厂1在山顶,工厂N在山脚.由于这座山处于 ...
- 【BZOJ1096】【ZJOI2007】仓库建设(斜率优化,动态规划)
[BZOJ1096][ZJOI2007]仓库建设(斜率优化,动态规划) 题面 Description L公司有N个工厂,由高到底分布在一座山上.如图所示,工厂1在山顶,工厂N在山脚.由于这座山处于高原 ...
- BZOJ1096 [ZJOI2007]仓库建设 动态规划 斜率优化
原文链接http://www.cnblogs.com/zhouzhendong/p/8696410.html 题目传送门 - BZOJ1096 题意 给定两个序列$a,b,X$,现在划分$a$序列. ...
- 【BZOJ1096】[ZJOI2007]仓库建设 斜率优化
[BZOJ1096][ZJOI2007]仓库建设 Description L公司有N个工厂,由高到底分布在一座山上.如图所示,工厂1在山顶,工厂N在山脚.由于这座山处于高原内陆地区(干燥少雨),L公司 ...
- 2016 华南师大ACM校赛 SCNUCPC 非官方题解
我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...
- noip2016十连测题解
以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...
- BZOJ-2561-最小生成树 题解(最小割)
2561: 最小生成树(题解) Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1628 Solved: 786 传送门:http://www.lyd ...
- Codeforces Round #353 (Div. 2) ABCDE 题解 python
Problems # Name A Infinite Sequence standard input/output 1 s, 256 MB x3509 B Restoring P ...
- 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解
题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...
随机推荐
- Android应用图标尺寸规范(转)
转自:http://blog.sina.com.cn/s/blog_4b20ae2e0101h84o.html Android Icon Size and Location for Apps DENS ...
- 解决Zookeeper报错:conf is not executed because it is not in the whitelist的解决办法
1.echo wchp | nc localhost 2181 ,通过路径列出服务器 watch 的详细信息,且它会输出一个与 session 相关的路径.但是出现下面的错误. [root@xg61 ...
- Android开发 VideoView视频播放详解
前言 VideoView是Android主要的视频播放View,它其实是对MediaPlayer的再次封装.如果你已经了解过MediaPlayer在使用VideoView是十分简单的.如果你想先了解M ...
- ES6(阮一峰) 数组的扩展
1.扩展运算符 扩展运算符(spread)是三个点(...).它好比 rest 参数的逆运算,将一个数组转为用逗号分隔的参数序列. console.log(1, ...[2, 3, 4], 5) // ...
- JDK1.8之后的新特性和新接口
接口的旧特性: 就特性下接口中只有: 常量(必须赋值) 抽象方法abstract(和final static private三个关键字冲突) interface Inter { //int a ; / ...
- css盒模型宽高混合计算calc
例如: .element{ width:calc(expression); } 兼容性:在IE9+.FF4.0+.Chrome19+.Safari6+都得到了较好支持,但是在移动端的支持不是很好. 其 ...
- Dart编程实例 - HelloWorld
Dart编程实例 - HelloWorld void main() { print('hello world'); } 本文转自:http://codingdict.com/article/23399
- iscroll refresh无效解决办法
最近用iscroll.js 写移动页面,效果还是挺好的.但,还是会遇到重新初始化的问题. var myScroll = new IScroll('#rule_wrapper',{ click:true ...
- 『Golang』—— 标准库之 time
... package main import ( "fmt" "time" ) func main() { time.AfterFunc(time.Milli ...
- 专题:NFSv4 file server
Network File System (NFS) is a file system protocol that allows client machines to access network at ...