Bzoj 1010: [HNOI2008] Toy packing toy--slope optimization

Source: Internet
Author: User

Bzoj 1010


The second slope optimization has a new understanding of the slope optimization. Happy (Foggy


The question is actually about slope optimization. Slope optimization. Slope optimization.

Okay, that's a naked question.



The node that we selected when we considered updating f[i]


If K is more superior than J


Then there are:

f[j]+ (j-i+sum[i]-sum[j]-l) ^2<f[k]+ (l+k-i+sum[i]-sum[k]-l) ^2

f[j]+ (Sum[i]-sum[j]) ^2-2* (i-j+l) * (Sum[i]-sum[j]) + (i-j+l) ^2<f[k]+ (Sum[i]-sum[k]) ^2+2* (i-k+l) * (Sum[i]-sum[k]) + (I-K+L) ^2

Make t1=i-j+l,t2=i-k+l;

f[j]+ (Sum[i]-sum[j]) ^2-2*t1* (Sum[i]-sum[j]) +t1^2<f[k]+ (Sum[i]-sum[k]) ^2-2*t2* (Sum[i]-sum[k]) +t2^2

f[j]-f[k]+ (Sum[i]-sum[j]) ^2-(Sum[i]-sum[k]) ^2+t1^2-t2^2<2*sum[i]* (SUM[K]-SUM[J]+K-J)


f[j]-f[k]+ (Sum[i]-sum[j]) ^2-(Sum[i]-sum[k]) ^2+t1^2-t2^2)/(2*SUM[K]-SUM[J]+K-J) <sum[i]


。。 Although this formula is very annoying, in fact, if you use Sum[i] to express sum[i]+i words is very convenient, but here I wrote a strict point


Well, Sum[i], the formula is as follows

(f[j]-f[k]+ (sum[j]+l) ^2+ (sum[k]+l) ^2)/((Sum[k]-sum[j]) <sum[i]


Okay, that's it.


Considering this thing is a slope equation, we ask for the minimum value, so the slope cannot be decremented.


Why. You might as well just update from the previous location because you're descending.


So we can maintain a lower convex hull according to this nature.


By the way, if the maximum value is to be maintained, the upper convex hull


Tween

Suddenly found that forgot to put the code ....

#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <queue&
Gt #include <string> #include <map> #include <set> #include <cstring> #include <ctime> # Include <vector> #define INF 1e9 #define EPS 1e-9 #define ITER multiset<ll>::iterator #define LL Long #d Efine MAXN 20010 #define for (i,j,k) for (ll i=j;i<=k;i++) #define DOW (I,j,k) for (ll i=k;i>=j;i--) using namespace std
;   inline void Read (ll &tx) {ll x=0,f=1;char Ch=getchar (); while (ch< ' 0 ' | |  Ch> ' 9 ') {if (ch== '-') F=-1;ch=getchar ();}  while (ch>= ' 0 ' &&ch<= ' 9 ') {x=x*10+ch-' 0 '; Ch=getchar ();} Tx=x*f;   } inline void Write (ll x) {if (x<0) Putchar ('-'), x=-x; if (x>=10) write (X/10);  Putchar (x%10+ ' 0 ');
} inline void Writeln (ll x) {write (x);p UTS ("");
ll n,l,a[100001],q[100001],l,r,f[100001]; inline ll Sqr (ll x) {return x*x;} inline double Get (ll y,ll x) {return (double) (F[X]-F[Y]+SQR (a[x]+l)-SQR (a[y]+l))/(2.0* (A[x]-a[y]));
	} int main () {read (n); Read (l); l++;
	for (i,1,n) read (A[i]);
	for (i,1,n) a[i]+=a[i-1]+1;
	l=r=1;q[1]=0;
		for (I,1,n) {while (L<r&&get (q[l],q[l+1]) <=a[i]) l++;
		F[I]=F[Q[L]]+SQR (A[I]-A[Q[L]]-L);
		while (L<r&&get (Q[r-1],q[r]) >get (q[r],i)) r--;
	Q[++r]=i;
} writeln (F[n]);	 }




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.