【BZOJ】【P1096】【ZJOI2007】【仓库建设】【题解】【斜率优化】
来源:互联网 发布:电脑记事本软件 编辑:程序博客网 时间:2024/05/17 09:14
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1096
我还是只会凸包+三分……
Code:
#include<bits/stdc++.h>using namespace std;typedef long long LL;const int maxn=1e6+5;struct point{LL x,y;point(LL _x=0,LL _y=0):x(_x),y(_y){}LL operator*(point oth)const{return x*oth.y-y*oth.x;}LL operator^(point oth)const{return x*oth.x+y*oth.y;}point operator-(point oth)const{return point(x-oth.x,y-oth.y);}};LL n;LL f[maxn];LL getint(){LL res=0;char c=getchar();while(!isdigit(c))c=getchar();while(isdigit(c))res=res*10+c-'0',c=getchar();return res;}struct CH{point ch[maxn];int m;CH():m(0){}void push_back(point p){while(m>1&&(ch[m-1]-ch[m-2])*(p-ch[m-1])<=0)m--;ch[m++]=p;}LL Qmin(point p){int l=0,r=m-1;while(r-l>2){int mid1=l+(r-l)/3;int mid2=r-(r-l)/3;if((p^ch[mid1])<(p^ch[mid2]))r=mid2;else l=mid1;}LL ans=1LL<<61;for(int i=l;i<=r;i++)ans=min(ans,p^ch[i]);return ans;}}C;LL c[maxn],p[maxn],x[maxn],sump[maxn],sumxp[maxn];int main(){n=getint();for(int i=1;i<=n;i++)x[i]=getint(),p[i]=getint(),c[i]=getint();for(int i=1;i<=n;i++)sumxp[i]=sumxp[i-1]+x[i]*p[i],sump[i]=sump[i-1]+p[i];//n++;C.push_back(point(0,0));f[1]=c[1];C.push_back(point(sump[1],f[1]+sumxp[1]));for(LL i=2;i<=n;i++){f[i]=1LL<<61;f[i]=C.Qmin(point(-x[i],1))+c[i]-sumxp[i-1]+x[i]*sump[i-1];C.push_back(point(sump[i],f[i]+sumxp[i]));}cout<<f[n]<<endl;return 0;}
0 0
- 【BZOJ】【P1096】【ZJOI2007】【仓库建设】【题解】【斜率优化】
- BZOJ P1096: [ZJOI2007]仓库建设
- BZOJ 斜率优化 1096: [ZJOI2007]仓库建设
- BZOJ 1096 ZJOI2007 仓库建设 斜率优化
- BZOJ 1096: [ZJOI2007]仓库建设(斜率优化)
- BZOJ 1096: [ZJOI2007]仓库建设 斜率优化
- BZOJ 1096: [ZJOI2007]仓库建设 斜率优化
- 斜率优化专题5——bzoj 1096 [ZJOI2007]仓库建设 题解
- bzoj 1096: [ZJOI2007]仓库建设 斜率优化+:DP
- [BZOJ]1096: [ZJOI2007]仓库建设 斜率优化DP
- 【BZOJ】1096 [ZJOI2007]仓库建设 dp+斜率优化
- BZOJ 1096 [ZJOI2007]仓库建设 斜率优化dp
- [BZOJ 1096][ZJOI2007]仓库建设:DP斜率优化
- BZOJ 1096 [ZJOI2007]仓库建设 动态规划+斜率优化
- 【斜率DP】【bzoj 1096】: [ZJOI2007]仓库建设
- 【ZJOI2007】【斜率优化DP】仓库建设
- [BZOJ1096][ZJOI2007][DP][斜率优化]仓库建设
- bzoj1096: [ZJOI2007]仓库建设 斜率优化DP
- java动态生成实例笔记<持续更新中>
- USB入门系列之七 —— USB的描述符及各种描述符之间的依赖关系【转】
- CRC(循环冗余校验算法)
- 解决WebLogic启动时BEA-171522异常(启动时报classcast exception)
- MFC的一些豆技巧
- 【BZOJ】【P1096】【ZJOI2007】【仓库建设】【题解】【斜率优化】
- Java实现文件的DES加密与解密算法
- kindeditor4.1.7 高度,宽度配置
- 列车调度(Train)
- Xcode 应用程序构建阶段(Build Phases)分析(2)
- jQuery.handleError is not a function
- JQ当前页面标签 高亮显示
- 常用正则表达式~~
- 前端工程师发展目标