zoukankan      html  css  js  c++  java
  • BZOJ 1096

    const maxm=1e100; 
          maxn=1000001; 
    var   f,x,p,c,sum,cost:array[0..maxn] of int64; 
          q:array[0..maxn] of longint; 
          n,i,h,t:longint; 
       
    function calc(j,i:longint):int64; 
    begin
       calc:=cost[i]-cost[j]-sum[j]*(x[i]-x[j]); 
    end; 
       
    function slope(j,k:longint):extended; 
    var tmp:int64; 
    begin
      tmp:=f[k]-f[j]-cost[k]+cost[j]+sum[k]*x[k]-sum[j]*x[j]; 
      if sum[k]=sum[j] then
       if tmp>=0 then exit(maxm) 
        else exit(-maxm); 
       slope:=tmp/(sum[k]-sum[j]); 
    end; 
       
    begin
      readln(n); 
      for i:=1 to n do readln(x[i],p[i],c[i]); 
      for i:=1 to n do sum[i]:=sum[i-1]+p[i]; 
      for i:=1 to n do
         cost[i]:=cost[i-1]+sum[i-1]*(x[i]-x[i-1]); 
      for i:=1 to n do
        begin
          while (h<t)and(slope(q[h],q[h+1])<x[i]) do inc(h); 
          f[i]:=f[q[h]]+calc(q[h],i)+c[i]; 
          while (h<t)and(slope(q[t-1],q[t])>slope(q[t],i)) do dec(t); 
          inc(t); q[t]:=i; 
        end; 
          writeln(f[n]); 
    end.
  • 相关阅读:
    20170728xlVba SSC_TODAY
    卸载angular版本
    union 共用体
    bootstrap的粗认识
    结构体,结构体数组,结构体指针
    C语言的枚举
    nodeJS 的认识
    nodejs 平台搭建
    动态表单
    指针
  • 原文地址:https://www.cnblogs.com/logichandsome/p/4054665.html
Copyright © 2011-2022 走看看