码迷,mamicode.com
首页 > 其他好文 > 详细

bzoj1010: [HNOI2008]玩具装箱toy

时间:2015-12-30 13:19:49      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:

窝只是来留坑的qwq

为毛double能过化成乘积式就过不了?

 

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<cstdlib>
 4 #include<algorithm>
 5 #include<iostream>
 6 
 7 using namespace std;
 8 
 9 void setIO(const string& s) {
10     freopen((s + ".in").c_str(), "r", stdin);
11     freopen((s + ".out").c_str(), "w", stdout);
12 }
13 template<typename Q> Q read(Q& x) {
14     static char c, f;
15     for(f = 0; c = getchar(), !isdigit(c); ) if(c == -) f = 1;
16     for(x = 0; isdigit(c); c = getchar()) x = x * 10 + c - 0;
17     if(f) x = -x;
18     return x;
19 }
20 template<typename Q> Q read() {
21     static Q x; read(x); return x;
22 }
23 
24 typedef long long LL;
25 const int N = 50000 + 10;
26 
27 LL f[N], k[N], c;
28 
29 LL sqr(const LL& x) {
30     return x * x;
31 }
32 
33 LL up(int i) {
34     return k[i] * (k[i] + c * 2) + f[i];
35 }
36 
37 LL up(int i, int j) {
38     return up(j) - up(i);
39 }
40 
41 LL down(int i, int j) {
42     return 2 * (k[j] - k[i]);
43 }
44 
45 double slope(int i, int j) {
46     return up(i, j) / down(i, j);
47 }
48 
49 int q[N];
50 
51 int main() {
52 #ifdef DEBUG
53     freopen("in.txt", "r", stdin);
54     freopen("out.txt", "w", stdout);
55 #endif
56     
57     int n;
58     read(n), read(c), ++c;
59     for(int i = 1; i <= n; i++) k[i] = k[i-1] + read<int>();
60     for(int i = 1; i <= n; i++) k[i] += i;
61     
62     int L = 0, R = 0;
63     q[R++] = 0;
64     for(int i = 1; i <= n; i++) {
65         while(L + 1 < R && k[i] > slope(q[L], q[L + 1])) L++;
66 //        while(L + 1 < R && k[i] * down(q[L], q[L + 1]) > up(q[L], q[L + 1])) L++;
67         int j = q[L];
68         f[i] = f[j] + sqr(k[i] - k[j] - c);
69         while(L + 1 < R && slope(q[R - 2], q[R - 1]) > slope(q[R - 2], i)) R--;
70 //        while(L + 1 < R && up(q[R - 2], q[R - 1]) * down(q[R - 2], i) > up(q[R - 2], i) * down(q[R - 2], q[R - 1])) R--;
71         q[R++] = i;
72     }
73     
74     printf("%lld\n", f[n]);
75     
76     return 0;
77 }

 

bzoj1010: [HNOI2008]玩具装箱toy

标签:

原文地址:http://www.cnblogs.com/showson/p/5088324.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!