您的位置:首页 > 其它

[HDOJ5461]Largest Point

2015-09-19 19:04 363 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5461

比赛的时候没敢多想,直接把八个情况全部枚举出来。

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long LL;
const int INF = 0x3f3f3f3f;
const int maxn = 5000000+100;

int t[maxn];
int n;
int a,b;

int main() {
int T;
scanf("%d",&T);
for(int tt = 1;tt <= T;++tt) {
scanf("%d %d %d",&n,&a,&b);
for(int i = 1;i <= n;++i) {
scanf("%d",&t[i]);
}
int maxx1 = 0,maxx2 = 0;
int mn1 = INF,mn2 = INF;
int mm1 = -INF,mm2 = -INF;
int nn1 = INF,nn2 = INF;
for(int i = 1;i <= n;++i) {
if(t[i] > mm1) {
mm2 = mm1;
mm1 = t[i];
}
else if(t[i] > mm2)
mm2 = t[i];

if(t[i] < nn1) {
nn2 = nn1;
nn1 = t[i];
}
else if(t[i] < nn2)
nn2 = t[i];
if(abs(t[i]) > abs(maxx1)) {
maxx2 = maxx1;
maxx1 = t[i];
}
else if(abs(t[i]) > abs(maxx2))
maxx2 = t[i];

if(abs(t[i]) < abs(mn1)) {
mn2 = mn1;
mn1 = t[i];
}
else if(abs(t[i]) < abs(mn2))
mn2 = t[i];

}
LL res1,res2;
if(a >= 0) {
res1 = (LL)a*maxx1*maxx1;
if(b >= 0) {
if(mm1 != maxx1) res1 += (LL)b*mm1;
else res1+= (LL)b*mm2;
}
else {
if(nn1 != maxx1) res1 += (LL)b*nn1;
else res1 += (LL)b*nn2;
}
}
else {
res1 = (LL)a*mn1*mn1;
if(b >= 0) {
if(mm1 != mn1) res1 += (LL)b*mm1;
else res1 += (LL)b*mm2;
}
else {
if(nn1 != mn1) res1 += (LL)b*nn1;
else res1 += (LL)b*nn2;
}
}
if(b >= 0) {
res2 = (LL)b*mm1;
if(a >= 0) {
if(maxx1 != mm1) res2 += (LL)a*maxx1*maxx1;
else res2 += (LL)a*maxx2*maxx2;
}
else {
if(mn1 != mm1) res2 += (LL)a*mn1*mn1;
else res2 += (LL)a*mn2*mn2;
}
}
else {
res2 = (LL)b*nn1;
if(a >= 0) {
if(maxx1 != nn1) res2 += (LL)a*maxx1*maxx1;
else res2 += (LL)a*maxx2*maxx2;
}
else {
if(mn1 != nn1) res2 += (LL)a*mn1*mn1;
else res2 += (LL)a*mn2*mn2;
}
}

printf("Case #%d: %I64d\n", tt, max(res1,res2));
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: