zoukankan      html  css  js  c++  java
  • Largest Point (2015沈阳赛区网络赛水题)

    Problem Description
    Given the sequence A with n integers t1,t2,,tn. Given the integral coefficients a and b. The fact that select two elements ti and tj of A and ij to maximize the value of at2i+btj, becomes the largest point.
    Input
    An positive integer T, indicating there are T test cases.
    For each test case, the first line contains three integers corresponding to n (2n5×106), a (0|a|106) and b (0|b|106). The second line contains n integers t1,t2,,tn where 0|ti|106 for 1in.

    The sum of n for all cases would not be larger than 5×106.
     
    Output
    The output contains exactly T lines.
    For each test case, you should output the maximum value of at2i+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
     
    题目大意:给出一系列的数t,给出a、b,找出最大的a*ti2+b*tj,其中,i<>j。
    题目分析:将a*ti2和b*tj分别存放在两个数组中,排下序并找出最大的。若两个最大的下标不相同,则和即为答案;若相同,再找两个次大的,求来自不同数组的最大的加次大的的和,再取二和之中大的便是答案。
     
     
    代码如下:
    # include<iostream>
    # include<cstdio>
    # include<cstring>
    # include<vector>
    # include<map>
    # include<set>
    # include<list>
    # include<cstdlib>
    # include<string>
    # include<iomanip>
    # include<algorithm>
    using namespace std;
    # define LL long double
    struct arr
    {
        LL val;
        int id;
        arr(){}
        arr(LL a,int b):val(a),id(b){}
        bool operator < (const arr& a) const {
            return val<a.val;
        }
    };
    arr w1[500005],w2[500005];
    int main()
    {
        int T,a,b,n,cas=0;
        scanf("%d",&T);
        while(T--)
        {
            int k;
            scanf("%d%d%d",&n,&a,&b);
            for(int i=0;i<n;++i){
                scanf("%d",&k);
                w1[i]=arr((LL)a*(LL)k*(LL)k,i);
                w2[i]=arr((LL)b*(LL)k,i);
            }
            sort(w1,w1+n);
            sort(w2,w2+n);
            printf("Case #%d: ",++cas);
            if(w1[n-1].id!=w2[n-1].id)
                cout<<fixed<<setprecision(0)<<w1[n-1].val+w2[n-1].val<<endl;
            else{
                LL ans1=w1[n-1].val+w2[n-2].val;
                LL ans2=w1[n-2].val+w2[n-1].val;
                cout<<fixed<<setprecision(0)<<max(ans1,ans2)<<endl;
            }
        }
        return 0;
    }
    

      

     
  • 相关阅读:
    BZOJ2705[SDOi2012]Longge的问题
    Ubuntu 18.04 打不开1.1.0版本网易云音乐的解决方法汇总
    BZOJ3295[CQOI2011]动态逆序对(CDQ分治)
    hdu-4638-Group(树状数组)
    hdu-3333-Turing Tree(树状数组)
    UVA-11983-Weird Advertisement(线段树+扫描线)[求矩形覆盖K次以上的面积]
    ZOJ-3597-Hit the Target!(线段树+扫描线)
    POJ-1177-Picture(线段树+扫描线+离散化)[矩形周长并]
    POJ-1151-Atlantis(线段树+扫描线+离散化)[矩形面积并]
    LightOJ 1135(线段树)
  • 原文地址:https://www.cnblogs.com/20143605--pcx/p/4822897.html
Copyright © 2011-2022 走看看