您的位置:首页 > 其它

【A了两道题的沈阳赛】2015 ACM/ICPC Asia Regional Shenyang Online

2015-09-20 20:48 323 查看
L - Largest Point

时限:1000MS 内存:32768KB 64位IO格式:%I64d & %I64u

问题描述

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.

输入

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.

输出

The output contains exactly T lines.

For each test case, you should output the maximum value of at2i+btj.

样例输入

2

3 2 1

1 2 3

5 -1 0

-3 -3 0 3 3

样例输出

Case #1: 20

Case #2: 0

#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<sstream>
#include<fstream>
#include<vector>
#include<map>
#include<stack>
#include<list>
#include<set>
#include<queue>
#define LL long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1 | 1
/*
正反循环的宏定义
*/
#define ffr(i,x,y) for(int i=(x),_en=(y);i<=_en;i++)
#define rff(i,x,y) for(int i=(x),_en=(y);i>=_en;i--)
#define clr(f,z) memset(f,z,sizeof(f))
using namespace std;
const int maxn=1000005,inf=1<<29;
int dir[][2]={ {0,1},{-1,0},{0,-1},{1,0},{-1,1},{-1,-1},{1,-1},{1,1}};//常用方向数组
vector<int>G[maxn];//常用邻接表
/*
函数重载,可根据参数类型,自动选择输入
*/
bool sf(int &x) { return scanf("%d",&x)==1;}
bool sf(char *x){return scanf("%s",x)==1;}
bool sf(double &x){return scanf("%lf",&x)==1;}
bool sf(LL &x) { return scanf("%I64d",&x)==1;}
void pf(int x,int op) {
    op?printf("%d\n",x):printf("%d ",x);//op==0打印数字加空格,op==1打印数字加换行
}
void pf(LL x,int op) {
    op?printf("%I64d\n",x):printf("%I64d ",x);//op==0打印数字加空格,op==1打印数字加换行
}
int get_rand(int n)
{
    return (int)((double)rand() / RAND_MAX * n) ;
}
LL a,b,num[maxn];
LL get(LL x,LL y)
{
    return a*x*x+b*y;
}
struct node{
    LL x;
    int id;
} A[maxn],B[maxn];
bool cmp(node a,node b)
{
    return a.x<b.x;
}
int main()
{
     //freopen("in.txt","r",stdin);
     //freopen("out.txt","w",stdout);
     //srand(time(NULL));
     int n,t,Case=1;
    sf(t);
    while(t--)
    {
        sf(n);sf(a);sf(b);
        //pf(n,0),pf(a,1),pf(b,1);
        ffr(i,0,n-1)
        {
            sf(num[i]);
            A[i].x=a*num[i]*num[i];
            A[i].id=i;
            B[i].x=b*num[i];
            B[i].id=i;
        }
        sort(A,A+n,cmp);sort(B,B+n,cmp);
        LL ans;
        if(A[n-1].id!=B[n-1].id) ans=A[n-1].x+B[n-1].x;
        else
        {
            ans=max(A[n-1].x+B[n-2].x,A[n-2].x+B[n-1].x);
        }
        printf("Case #%d: %I64d\n",Case++,ans);
    }
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: