2015 ACM/ICPC Asia Regional Shenyang Online-1012 Largest Point

Largest Point

Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0


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
 
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
const long long N=5000010;
int num[N];
typedef struct AA
{
    long long f;//保存ati^2
    long long Count;//保存编号
} A;
A s[N];
typedef struct BB
{
    long long ff;//保存btj
    long long ccount;//保存编号
} B;
B ss[N];
int cmp(const void* x1,const void* y1)//ati^2降序
{
    A* x=(A*)x1;
    A* y=(A*)y1;
    long long m=y->f-x->f;
    return m;
}
int com(const void* x1,const void* y1)//btj降序
{
    B* x=(B*)x1;
    B* y=(B*)y1;
    long long m=y->ff-x->ff;
    return m;
}
int main()
{
    long long c,n,a,b,i,cnt=1;
    long long sum;
    scanf("%d",&c);
    while(c--)
    {
        sum=0;
        scanf("%d%d%d",&n,&a,&b);
        for(i=0; i<n; ++i)//输入处理保存数据
        {
            scanf("%d",&num[i]);
            s[i].f=a*num[i]*num[i];
            ss[i].ff=b*num[i];
            s[i].Count=i;
            ss[i].ccount=i;
        }
        qsort(s,n,sizeof(AA),cmp);//排序
        qsort(ss,n,sizeof(BB),com);
        if(s[0].Count==ss[0].ccount)//如果最大的两个数编号相同
        {
            if((s[0].f+ss[1].ff)>(s[1].f+ss[0].ff))
                sum=s[0].f+ss[1].ff;
            else
                sum=s[1].f+ss[0].ff;
        }
        else
            sum=s[0].f+ss[0].ff;
        printf("Case #%d: %I64d\n",cnt++,sum);
    }
    return 0;
}

嗯,所有数据都要用long long。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值