Descriptioninput the first row of two positive integers n, S, respectively, indicating the number of days the small Y can predict and the initial amount of money. Next n lines, the K line three real AK, BK, Ratek, meaning as described in the title output has only a real maxprofit, indicating the maximum amount of money that can be obtained at the end of the nth day operation. The answer retains 3 decimal places. Sample Input3 100
1 1 1
1 2 2
2 2 3Sample Output225.000HINT
The test data is designed so that the accuracy error does not exceed 10-7.
For 40% of test data, meet n≤10;
For 60% of test data, meet N≤1 000;
For 100% of test data, meet N≤100 000;
Note that it is not possible to maintain a monotonic queue because X and slope are not monotonous.
Based on this we are going to divide this slope dp with a balance tree or a CDP.
CDQ Paper->click here
1#include <cmath>2#include <cstdio>3#include <cstring>4#include <algorithm>5 using namespacestd;6 7 Const intN = 1e5+Ten;8 Const DoubleINF =1e20;9 Const DoubleEPS = 1e-8;Ten One structPt { A DoubleX,y,a,b,k,r; - intID; - BOOL operator< (Constpt& RHS)Const { the returnK>RHS.K; - } - }p[n],t[n]; - + DoubleF[n]; - intN,top,st[n]; + A DoubleSlopintAintb) at { - if(!B)return-inf; - if(Fabs (p[a].x-p[b].x) <eps)returninf; - return(P[B].Y-P[A].Y)/(p[b].x-p[a].x); - } - voidSolveintLintR) in { - if(l==r) { toF[l]=max (f[l],f[l-1]); +p[l].y=f[l]/(p[l].a*p[l].r+p[l].b); -p[l].x=p[l].y*P[L].R; the return ; * } $ intMid= (l+r) >>1, j=1, l1=l,l2=mid+1;Panax Notoginseng for(inti=l;i<=r;i++) { - if(P[i].id<=mid) t[l1++]=P[i]; the Elset[l2++]=P[i]; + } A for(inti=l;i<=r;i++) p[i]=T[i]; the solve (l,mid); +top=0; - for(inti=l;i<=mid;i++) { $ while(top>1&&slop (st[top-1],st[top]) <slop (st[top-1],i) +eps) top--; $st[++top]=i; - } -st[++top]=0; the for(intI=mid+1; i<=r;i++) { - while(J<top&&slop (st[j],st[j+1]) +EPS>P[I].K) J + +;WuyiF[p[i].id]=max (f[p[i].id],p[st[j]].x*p[i].a+p[st[j]].y*p[i].b); the } -Solve (mid+1, R); WuL1=l,l2=mid+1; - for(inti=l;i<=r;i++) { About if(((p[l1].x<p[l2].x| | (Fabs (p[l1].x-p[l2].x) <eps&&p[l1].y<p[l2].y)) | | L2>R) &&l1<=mid) $t[i]=p[l1++]; - Elset[i]=p[l2++]; - } - for(inti=l;i<=r;i++) p[i]=T[i]; A } + the intMain () - { $scanf"%D%LF", &n,&f[0]); the for(intI=1; i<=n;i++) { thescanf"%LF%LF%LF",&p[i].a,&p[i].b,&P[I].R); thep[i].k=-p[i].a/p[i].b; P[i].id=i; the } -Sort (p+1, p+n+1); inSolve1, n); theprintf"%.3LF", F[n]); the return 0; About}
Bzoj 1492 [NOI2007] currency exchange cash (slope dp+cdq divide)