BZOJ1492: [NOI2007] Currency exchange cash

Source: Internet
Author: User

Title: http://www.lydsy.com/JudgeOnline/problem.php?id=1492

F[i]=max (F[i-1],x[j]*a[i]+y[j]*b[i]) F[i] represents the maximum profit, X[j],y[j] represents the maximum number of A/b coupons that can be swapped in J days respectively.

In slope optimization, if the slope of each state is monotonous, the x-coordinate of the point on the convex hull, the y-coordinate is monotonous. That last monotonous queue would be all right.

The slope given in this question and the x-coordinate on the convex hull are not monotonous ...

(Because the balance tree will not be written to maintain dynamic convex hull so wrote CDQ division.)

In fact... It's better to look at the paper honestly.

I'll just say a few words. Tat. The points that are inserted first contribute to the following points: If the point x, y coordinates on the convex hull can be ordered, the interval slope of the inquiry is orderly. Then you can maintain a stack ah or something.

So first to the slope of the order, divided by time into the left and right two intervals, the left side of the violence to make a convex bag, to ask questions. Finally, the two intervals are combined by x, Y (so the x, y coordinates are spicy).

#include <cstring>#include<iostream>#include<cstdio>#include<algorithm>#include<queue>#include<map>#include<cmath>#defineRep (i,l,r) for (int i=l;i<=r;i++)#defineDown (i,l,r) for (int i=l;i>=r;i--)#defineCLR (x, y) memset (x,y,sizeof (×))#defineMAXN 100500#defineINF Int (1E9)#definell Long Long#defineEPS 1e-9using namespacestd;structdata{DoubleK,a,b,x,y,r;intID;} A[MAXN],T[MAXN];intN,S[MAXN];DoubleF[MAXN];intRead () {intx=0, f=1;CharCh=GetChar ();  while(!isdigit (CH)) {if(ch=='-') f=-1; Ch=GetChar ();}  while(IsDigit (CH)) {x=x*Ten+ch-'0'; Ch=GetChar ();} returnx*F;} BOOLCMP (data a,data b) {returnA.k>B.K;}DoubleGETK (intAintB) {    if(! Breturn-1e20; if(Fabs (a[a].x-a[b].x) <eps)return1e20; return(A[B].Y-A[A].Y)/(a[b].x-a[a].x);}intCross (Data a,data b,data c) {Doublex1=b.x-a.x,y1=b.y-a.y,x2=c.x-a.x,y2=c.y-a.y; if(Fabs (x1*y2-x2*y1) <eps)return 0; if(x1*y2-x2*y1>0)return 1; return-1;}voidCdqintLintR) {    if(l==R) {F[l]=max (f[l],f[l-1]); A[l].y=f[l]/(a[l].a*a[l].r+a[l].b); a[l].x=a[l].r*a[l].y; return; }    intL1=l,l2= (L+R)/2+1, mid= (L+R)/2, j=1; Rep (I,l,r)if(A[i].id<=mid) t[l1++]=a[i];Elset[l2++]=A[i]; Rep (i,l,r) a[i]=T[i];    CDQ (L,mid); inttop=0; Rep (i,l,mid) { while(top>1&&cross (a[s[top-1]],a[s[top]],a[i]) >=0) top--; s[++top]=i; } s[++top]=0; Rep (I,mid+1, R) {         while(J&LT;TOP&AMP;&AMP;GETK (s[j],s[j+1]) +EPS&GT;A[I].K) J + +; intnow=a[i].id; F[now]=max (f[now],a[i].a*a[s[j]].x+a[i].b*a[s[j]].y); } CDQ (Mid+1, R); L1=l,l2=mid+1; Rep (I,l,r)if(l1<=mid&& (a[l1].x<a[l2].x| | (Fabs (a[l1].x-a[l2].x) <eps&&a[l1].y<a[l2].y) | | L2&GT;R)) t[i]=a[l1++];Elset[i]=a[l2++]; Rep (i,l,r) a[i]=t[i];}intMain () {n=read (); scanf"%LF", &f[0]); Rep (I,1, N) {scanf ("%LF%LF%LF", &AMP;A[I].A,&AMP;A[I].B,&AMP;A[I].R); A[i].id=i; A[I].K=-a[i].a/a[i].b; } sort (A+1, A +1+n,cmp); CDQ (1, N); printf ("%.3lf\n", F[n]); return 0;}

BZOJ1492: [NOI2007] Currency exchange cash

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.