标签:class 第一个 dcl span insert abs font stream tty
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 100010
#define eps 1e-9
#define INF 0x7fffffff
using namespace std;
typedef long long ll;
int n;
double f[N];
int stack[N];
struct node
{
double x,y,a,b,rate,k;
int w;
}p[N],t[N];
int cmp(node a,node b)
{
return a.k>b.k;
}
double getk(int a,int b)
{
if(!b)return -INF;
if(fabs(p[a].x-p[b].x)<eps)return INF;
return (p[b].y-p[a].y)/(p[b].x-p[a].x);
}
void solve(int l,int r)
{
if(l==r)
{
f[l]=max(f[l-1],f[l]);
p[l].y=f[l]/(p[l].a*p[l].rate+p[l].b);
p[l].x=p[l].rate*p[l].y;
return;
}
int mid=(l+r)>>1;
int l1=l,l2=mid+1,pt=1;
for(int i=l;i<=r;i++)
{
if(p[i].w<=mid)t[l1++]=p[i];
else t[l2++]=p[i];
}
for(int i=l;i<=r;i++)p[i]=t[i];
solve(l,mid);
int top=0;
for(int i=l;i<=mid;i++)
{
while(top>1&&getk(stack[top-1],stack[top])<=getk(stack[top],i))top--;
stack[++top]=i;
}
stack[++top]=0;
for(int i=mid+1;i<=r;i++)
{
while(pt<top&&getk(stack[pt],stack[pt+1])>p[i].k)pt++;
f[p[i].w]=max(f[p[i].w],p[stack[pt]].x*p[i].a+p[stack[pt]].y*p[i].b);
}
solve(mid+1,r);
l1=l,l2=mid+1;
for(int i=l;i<=r;i++)
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++];
else t[i]=p[l2++];
for(int i=l;i<=r;i++)p[i]=t[i];
}
int main()
{
scanf("%d%lf",&n,&f[0]);
for(int i=1;i<=n;i++)
{
scanf("%lf%lf%lf",&p[i].a,&p[i].b,&p[i].rate);
p[i].k=-p[i].a/p[i].b;
p[i].w=i;
}
sort(p+1,p+1+n,cmp);
solve(1,n);
printf("%.3lf\n",f[n]);
}
标签:class 第一个 dcl span insert abs font stream tty
原文地址:http://www.cnblogs.com/gccbuaa/p/7119471.html