hdu5461(2015 ACM/ICPC Asia Regional Shenyang Online)

来源:互联网 发布:车铣复合c轴编程实例 编辑:程序博客网 时间:2024/05/21 21:55
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
23 2 11 2 35 -1 0-3 -3 0 3 3
 

Sample Output
Case #1: 20Case #2: 0
 

Source
2015 ACM/ICPC Asia Regional Shenyang Online
 

Recommend
wange2014   |   We have carefully selected several similar problems for you:  5467 5466 5465 5464 5463 
 网络赛的签到题,排个序,然后在判断一下是否使用了同一个数,值得注意的是虽然a,b比较小,但需要定义成long long,因为t的平方会爆int;
代码
#include <iostream>#include <stdio.h>#include <algorithm>using namespace std;const int maxn=5000100;int t[maxn];struct hehe{  long long num;  int id;}aa[maxn],bb[maxn];long long cmp(hehe a,hehe b){ return a.num>b.num;}int main(){    int T,n,flag=0;    long long tmp1,tmp2,tmp,a,b;    scanf("%d",&T);    while(T--)    {     flag++;     scanf("%d%lld%lld",&n,&a,&b);     for(int i=0;i<=n-1;i++)      scanf("%d",&t[i]);     for(int i=0;i<=n-1;i++)     {      aa[i].num=a*t[i]*t[i];      aa[i].id=i;      bb[i].num=b*t[i];      bb[i].id=i;     }     sort(aa,aa+n,cmp);     sort(bb,bb+n,cmp);     if(aa[0].id!=bb[0].id)      printf("Case #%d: %lld\n",flag,aa[0].num+bb[0].num);     else     {     tmp1=aa[0].num+bb[1].num;     tmp2=aa[1].num+bb[0].num;     tmp=(tmp1>tmp2)?tmp1:tmp2;      printf("Case #%d: %lld\n",flag,tmp);     }    }    return 0;}

0 0
原创粉丝点击