HDU 5461 Largest point

Source: Internet
Author: User

Problem Descriptiongiven the sequenceAWithNIntegersT1,T2,?,tn . Given the integral coefficientsaandb. The fact that select the elementsTi andTJ OfAandi≠j To maximize the value of at2i+btJ, becomes the Largest point.

Inputan positive integerT, indicating there isTTest cases.
For each test case, the first line contains three integers corresponding toN(2≤N≤5X106) ,  a  ( 0≤ | a| ≤106) andb (0≤| b| ≤6) . The second line containsNIntegersT1,T2,?,tn where0≤| TI| ≤6 For1≤i≤n .

The sum of n For all cases would is larger than 5x6.

Outputthe output contains exactlyt  lines.
For each test case, you should output the maximum value Of  at2i+b tj .

Sample Input23 2 2 35-1 0-3-3 0 3 3Sample outputcase #1: Case #2:0 Data range is small, direct violence solution
#include <iostream>#include<cstdio>#include<cstring>#include<stack>#include<queue>#include<map>#include<Set>#include<vector>#include<cmath>#include<algorithm>using namespacestd;Const DoubleEPS = 1e-6;Const DoublePI = ACOs (-1.0);Const intINF =0x3f3f3f3f;Const intMOD =1000000007;#definell Long Long#defineCL (a) memset (A,0,sizeof (a))intt;ll n,a,b;ll t[1000010];ll min1,min2,max1,max2,k;//The smallest number, the second small number, the largest number, the second largest number, and the nearest 0 number, respectively.intMain () {scanf ("%d",&T); intD=1;  while(t--) {scanf ("%lld%lld%lld",&n,&a,&b); K=INF;  for(intI=0; i<n; i++) scanf ("%lld",&T[i]); printf ("Case #%d:", d++); Sort (T, T+N);  for(intI=0; i<n; i++)        {            if(t[i]<=0&&t[i+1]>=0) K=min (-t[i], t[i+1]); } min1=t[0]; Min2=t[1]; Max1=t[n-1]; Max2=t[n-2];//find these five numbers .        if(a<0&&b<0)//then the bitter force to find the biggest solution, notice the negative square is a positive numberprintf ("%lld\n", a*k*k+b*min1); Else if(a<0&&b>0) printf ("%lld\n", a*k*k+b*max1); Else if(a>0&&b<0) printf ("%lld\n", Max (Max (a*max1*max1+b*min1, a*min1*min1+b*min2), a*min2*min2+b*min1)); Else if(a>0&&b>0) printf ("%lld\n", Max (Max (A*MAX1*MAX1+B*MAX2, a*max2*max2+b*max1), a*min1*min1+b*max1)); Elseprintf ("0\n"); }    return 0;}

HDU 5461 Largest point

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.