zoukankan      html  css  js  c++  java
  • bzoj 1911: [Apio2010]特别行动队

    呃呃呃,和平方的有什么区别吗。。

     1 #include <bits/stdc++.h>
     2 #define LL long long
     3 #define lowbit(x) x&(-x)
     4 #define inf 0x3f3f3f3f
     5 #define eps 1e-5
     6 #define N 1000005
     7 using namespace std;
     8 inline int ra()
     9 {
    10     int x=0,f=1; char ch=getchar();
    11     while (ch<'0' || ch>'9') {if (ch=='-') f=-1; ch=getchar();}
    12     while (ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();}
    13     return x*f;
    14 }
    15 LL sum[N],f[N];
    16 int A,B,C,n,q[N];
    17 double slope(int j, int k)
    18 {
    19     return (double)((f[j]+A*sum[j]*sum[j]-B*sum[j])-(f[k]+A*sum[k]*sum[k]-B*sum[k]))/(double)(2*A*(sum[j]-sum[k]));
    20 }
    21 int main(int argc, char const *argv[])
    22 {
    23     n=ra(); A=ra(); B=ra(); C=ra();
    24     for (int i=1; i<=n; i++) sum[i]=sum[i-1]+ra();
    25     int l=0,r=0;
    26     for (int i=1; i<=n; i++)
    27     {
    28         while (l<r && slope(q[l+1],q[l])<=(double)sum[i]) l++;
    29         int t=q[l];
    30         f[i]=f[t]+A*(sum[i]-sum[t])*(sum[i]-sum[t])+B*(sum[i]-sum[t])+C;
    31         while (l<r && slope(q[r],q[r-1])>=slope(i,q[r])) r--;
    32         q[++r]=i;
    33     }
    34     cout<<f[n];
    35     return 0;
    36 }
  • 相关阅读:
    数据结构入门
    C语言入门-全局变量
    C语言入门-类型定义
    C++ 名称空间嵌套
    C++ 名称空间
    C++ 一些术语
    C++ new初始化与定位new运算符
    网络时间自动同步工具
    C++ 语言链接性
    C++ 函数和链接性
  • 原文地址:https://www.cnblogs.com/ccd2333/p/6523066.html
Copyright © 2011-2022 走看看