[HDU 3507] Print Article
来源:互联网 发布:相对湿度数据 编辑:程序博客网 时间:2024/06/02 02:19
Problem Link
这题应该可以算是斜率优化
Description
给定
Solution
这道题显然是道
然而
设
也就是说,只要满足了这个条件,
1.当
2.假如
我们在
Code
#include<stdio.h>#include<string.h>#include<algorithm>#include<iostream>#define N 500005#define ll long longusing namespace std;template <class T>inline void Rd(T &res){ char c;res=0;int k=1; while(c=getchar(),c<48&&c!='-'); if(c=='-'){k=-1;c='0';} do{ res=(res<<3)+(res<<1)+(c^48); }while(c=getchar(),c>=48); res*=k;}template <class T>inline void Pt(T res){ if(res<0){ putchar('-'); res=-res; } if(res>=10)Pt(res/10); putchar(res%10+48);}int n,m;int A[N];int dp[N];int x[N],y[N];int Q[N];int getup(int k,int j){ return y[j]-y[k];}int getdown(int k,int j){ return x[j]-x[k];}int calc(int j,int i){ return dp[j]+(A[i]-A[j])*(A[i]-A[j])+m;}int main(){ while(scanf("%d",&n)!=EOF){ Rd(m); for(int i=1;i<=n;i++){ Rd(A[i]); A[i]+=A[i-1]; } int L=0,R=0; Q[R++]=0; dp[0]=0; for(int i=1;i<=n;i++){ while(L+1<R&&getup(Q[L],Q[L+1])<=getdown(Q[L],Q[L+1])*A[i])L++; dp[i]=calc(Q[L],i); x[i]=2*A[i]; y[i]=dp[i]+A[i]*A[i]; while(L+1<R&&getup(Q[R-1],i)*getdown(Q[R-2],Q[R-1])<=getup(Q[R-2],Q[R-1])*getdown(Q[R-1],i))R--; Q[R++]=i; } Pt(dp[n]); putchar('\n'); } return 0;}
- hdu-3507-Print Article
- hdu 3507 Print Article
- hdu 3507 Print Article
- HDU 3507 Print Article
- 【HDU 3507】 Print Article
- hdu 3507Print Article
- hdu-3507 Print Article
- HDU 3507 Print Article
- HDU 3507 Print Article
- HDU 3507 Print Article
- Print Article[HDU 3507]
- HDU 3507 Print Article
- hdu 3507 Print Article
- hdu 3507 Print Article
- Hdu-3507 Print Article
- HDU 3507 Print Article
- [HDU 3507] Print Article
- hdu 3507 Print Article
- mapreduce 中文版 中文翻译
- hp中cookie实现二级域名可访问操作的方法
- 【c++】stl顺序容器
- Native.js 原生方法-拨打电话
- vue-router的两种模式的区别
- [HDU 3507] Print Article
- Mysql replication设置
- 框架思想的资料汇总
- 微信小程序--后端管理平台8页面json数据显示
- java--Scanner
- devexpress控件中的gridControl设置某个单元格属性
- Android应用开发入门【个人笔记】
- 泛型
- windows之explorer.exe无法安装,请联系你的软件供应商