Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5461
When the game did not dare to think, directly eight cases all enumerated.
1#include <cstdio>2#include <cstring>3#include <algorithm>4#include <cmath>5 using namespacestd;6 7typedefLong LongLL;8 Const intINF =0x3f3f3f3f;9 Const intMAXN =5000000+ -;Ten One intT[MAXN]; A intN; - intb; - the intMain () { - intT; -scanf"%d",&T); - for(inttt =1; TT <= t;++TT) { +scanf" %d%d%d",&n,&a,&b); - for(inti =1; I <= n;++i) { +scanf"%d",&t[i]); A } at intMAXX1 =0, maxx2 =0; - intMn1 = Inf,mn2 =INF; - intMM1 =-inf,mm2 =-INF; - intNN1 = INF,NN2 =INF; - for(inti =1; I <= n;++i) { - if(T[i] >mm1) { inmm2 =mm1; -MM1 =T[i]; to } + Else if(T[i] >mm2) -mm2 =T[i]; the * if(T[i] <nn1) { $NN2 =nn1;Panax NotoginsengNN1 =T[i]; - } the Else if(T[i] <nn2) +NN2 =T[i]; A if(ABS (T[i]) >ABS (MAXX1)) { theMAXX2 =maxx1; +MAXX1 =T[i]; - } $ Else if(ABS (T[i]) >ABS (MAXX2)) $MAXX2 =T[i]; - - if(ABS (T[i]) <ABS (MN1)) { theMn2 =Mn1; -Mn1 =T[i];Wuyi } the Else if(ABS (T[i]) <ABS (MN2)) -Mn2 =T[i]; Wu - } About LL Res1,res2; $ if(A >=0) { -Res1 = (LL) a*maxx1*maxx1; - if(b >=0) { - if(mm1! = maxx1) Res1 + = (LL) b*mm1; A Elseres1+= (LL) b*mm2; + } the Else { - if(nn1! = maxx1) Res1 + = (LL) b*nn1; $ ElseRes1 + = (LL) b*nn2; the } the } the Else { theRes1 = (LL) a*mn1*Mn1; - if(b >=0) { in if(mm1! = mn1) Res1 + = (LL) b*mm1; the ElseRes1 + = (LL) b*mm2; the } About Else { the if(nn1! = mn1) Res1 + = (LL) b*nn1; the ElseRes1 + = (LL) b*nn2; the } + } - if(b >=0) { theRes2 = (LL) b*mm1;Bayi if(A >=0) { the if(maxx1! = mm1) Res2 + = (LL) a*maxx1*maxx1; the ElseRes2 + = (LL) a*maxx2*maxx2; - } - Else { the if(Mn1! = mm1) Res2 + = (LL) a*mn1*Mn1; the ElseRes2 + = (LL) a*mn2*Mn2; the } the } - Else { theRes2 = (LL) b*nn1; the if(A >=0) { the if(maxx1! = nn1) Res2 + = (LL) a*maxx1*maxx1;94 ElseRes2 + = (LL) a*maxx2*maxx2; the } the Else { the if(Mn1! = nn1) Res2 + = (LL) a*mn1*Mn1;98 ElseRes2 + = (LL) a*mn2*Mn2; About } - }101 102printf"Case #%d:%i64d\n", TT, MAX (res1,res2));103 }104 return 0; the}
[HDOJ5461] Largest point