hdu 5461 Largest Point

本文介绍了一种算法问题——最大点数问题,该问题要求在给定的整数序列中选择两个不同的元素,并通过特定公式计算得出最大点数。文章详细解释了输入输出格式及示例,并提供了一个实现该算法的C++代码示例。

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 i≠j 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 (2≤n≤5×106), a (0≤|a|≤106) and b (0≤|b|≤106). The second line contains n integers t1,t2,⋯,tn where 0≤|ti|≤106 for 1≤i≤n.

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

Source
2015 ACM/ICPC Asia Regional Shenyang Online

Recommend
wange2014

#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<bits/stdc++.h>
#define ll long long
using namespace std;
struct nana
{
    long long m,n;
}A[500010],B[500010];
int cmp(nana a,nana b)
{
    return a.m<b.m;
}
int main()
{
    int T;
    ll flag=0;
    scanf("%d",&T);
    while(T--)
    {
        ll n,a,b,t;
        scanf("%lld%lld%lld",&n,&a,&b);
        for(ll i=0;i<n;i++)
        {
            scanf("%lld",&t);
            A[i].m=a*t*t;
            A[i].n=i;
            B[i].m=b*t;
            B[i].n=i;
        }
        sort(A,A+n,cmp);
        sort(B,B+n,cmp);
        printf("Case #%lld: %lld\n",++flag,(A[n-1].n==B[n-1].n)?(max(A[n-1].m+B[n-2].m,A[n-2].m+B[n-1].m)):(A[n-1].m+B[n-1].m));
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值