Print Article[HDU 3507]
来源:互联网 发布:mt4软件kdj指标 编辑:程序博客网 时间:2024/05/20 21:22
Problem Description
Zero has an old printer that doesn’t work well sometimes. As it is antique, he still like to use it to print articles. But it is too old to work for a long time and it will certainly wear and tear, so Zero use a cost to evaluate this degree.
One day Zero want to print an article which has
Now Zero want to know the minimum cost in order to arrange the article perfectly.
Input Description
There are many test cases. For each test case, There are two numbers
Output Description
A single number, meaning the mininum cost to print the article.
Sample Input
5 5
5
9
5
7
5
Sample Output
230
I Think
设
现在考虑当
设
对于两个决策
Code
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int Size = 500010;int que[Size];int a[Size];int f[Size];int s[Size];int n,m;int H,T;int x(int,int);int y(int,int);int main(){ while(scanf("%d%d",&n,&m)!=EOF){ for(int i=1;i<=n;++i){ scanf("%d",&a[i]); s[i] = s[i-1]+a[i]; } H = que[0] = 0; T = 1; for(int i=1;i<=n;++i){ while(H+1<T && y(que[H+1],que[H])<=s[i]*x(que[H+1],que[H])) ++H; f[i] = f[que[H]]+m+(s[i]-s[que[H]])*(s[i]-s[que[H]]); while(H+1<T && y(i,que[T-1])*x(que[T-1],que[T-2])<=y(que[T-1],que[T-2])*x(i,que[T-1])) --T; que[T++] = i; } printf("%d\n",f[n]); } return 0;}int x(int i,int j){ return (s[i]-s[j])*2;}int y(int i,int j){ return f[i]+s[i]*s[i]-f[j]-s[j]*s[j];}
- 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
- CUICatalog: Invalid asset name supplied:
- Zynq AXI Dual Bram 操作实例
- 逻辑回归Python代码
- fdisk
- Android 内部类实现点击事件举例
- Print Article[HDU 3507]
- JDK1.8安装配置
- Javascript异步编程的4种方法
- C++程序设计语言练习11.4 算术运算符重载的友元写法
- android stuido You can quickly navigate in the currently edited file with Ctrl+F12 (Navigate | File
- iOS开发之第三方支付微信支付教程,史上最新最全第三方微信支付方式实现、微信集成教程,微信实现流程
- bootstrap inputfile.js
- mysql.user字段含义
- 指针数组和数组指针