http://acm.hdu.edu.cn/showproblem.php?pid=5461
分析:一开始很撒很撒的分了很多种情况去写了,后来发现可以先储存a*num*num和b*num的值,然后再判断最大值。。
#include <iostream> #include <stdio.h> #include <string.h> #include <string> #include <vector> #include <algorithm> #include <map> #include <queue> #include <stack> #include <math.h> using namespace std; #define met(a, b) memset(a, b, sizeof(a)) const int maxn=5000007; #define oo 0x3f3f3f3f const int MOD = 1e9+7; typedef long long LL; int num[maxn]; struct node { LL sum; int index; }a[maxn], b[maxn]; int cmp(node p, node q) { return p.sum>q.sum; } int main() { int T, n, A, B, cnt=1; LL num; scanf("%d", &T); while(T --) { scanf("%d %d %d", &n, &A, &B); for(int i=0; i<n; i++) { scanf("%lld", &num); a[i].sum=A*num*num; a[i].index = i; b[i].sum=B*num; b[i].index = i; } sort(a, a+n, cmp); sort(b, b+n, cmp); if(a[0].index != b[0].index) printf("Case #%d: %lld\n", cnt++, a[0].sum+b[0].sum); else { LL p = max(a[0].sum+b[1].sum, a[1].sum+b[0].sum); printf("Case #%d: %lld\n",cnt++, p); } } return 0; }
时间: 2024-10-08 15:47:40