zoukankan      html  css  js  c++  java
  • HDU 5461

    Given the sequence AA with nn integers t1,t2,,tnt1,t2,⋯,tn. Given the integral coefficients aaand bb. The fact that select two elements titi and tjtj of AA and iji≠j to maximize the value of at2i+btjati2+btj, becomes the largest point.

    InputAn positive integer TT, indicating there are TT test cases. 
    For each test case, the first line contains three integers corresponding to n (2n5×106), a (0|a|106)n (2≤n≤5×106), a (0≤|a|≤106) and b (0|b|106)b (0≤|b|≤106). The second line contains nnintegers t1,t2,,tnt1,t2,⋯,tn where 0|ti|1060≤|ti|≤106 for 1in1≤i≤n. 

    The sum of nn for all cases would not be larger than 5×1065×106.
    OutputThe output contains exactly TT lines. 
    For each test case, you should output the maximum value of at2i+btjati2+btj.
    Sample Input

    2
    
    3 2 1
    1 2 3
    
    5 -1 0
    -3 -3 0 3 3

    Sample Output

    Case #1: 20
    Case #2: 0

    只需要维护一下a*t*t和b*t各自的最大和次大值。然后记录最大值对应的下标,以此来判断冲突。
    当时没有想清楚,以至于维护了太多最值,把自己搞乱了,也和最近身体状态有关吧。

    #include<cstdio>
    #include<algorithm>
    using namespace std;
    #define ll long long
    const ll inf = 1000000000000000000ll;
    int main(){
        int t;
        scanf("%d",&t);
        for(int i=1;i<=t;i++){
            ll n, a, b, t;
            ll max1a=-inf,max2a=-inf,max1b=-inf,max2b=-inf;
            int x=-1, y=-1;
            scanf("%lld%lld%lld",&n,&a,&b);
            for(int i=0;i<n;i++){
                scanf("%lld",&t);
                if(a*t*t>max1a){
                    x = i;
                    max2a = max1a;
                    max1a = a*t*t;
                }else if(a*t*t>max2a){
                    max2a = a*t*t;
                }
                if(b*t>max1b){
                    y = i;
                    max2b = max1b;
                    max1b = b*t;
                }else if(b*t>max2b){
                    max2b = b*t;
                }
            }
            printf("Case #%d: ",i);
            if(x==y){
                printf("%lld
    ",max(max1a+max2b,max2a+max2b));
            }else
                printf("%lld
    ",max1a+max1b);
        }
        return 0;
    }
    View Code


  • 相关阅读:
    python
    VSCompile
    Oracle学习
    CMD
    JQuery 学习
    单词
    解决Manjaro+win双系统相差8小时
    编辑器使用
    软件安装
    磁盘分区与逻辑卷管理
  • 原文地址:https://www.cnblogs.com/kongbb/p/11349072.html
Copyright © 2011-2022 走看看