码迷,mamicode.com
首页 > 其他好文 > 详细

hdu5461 Largest Point(沈阳网赛)

时间:2015-09-20 17:52:28      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:水   网络赛   

Largest Point

Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 536 Accepted Submission(s): 230


Problem Description
Given the sequence A技术分享 with n技术分享 integers t技术分享1技术分享,t技术分享2技术分享,?,t技术分享n技术分享技术分享. Given the integral coefficients a技术分享 and b技术分享. The fact that select two elements t技术分享i技术分享技术分享 and t技术分享j技术分享技术分享 of A技术分享 and i≠j技术分享 to maximize the value of at技术分享2技术分享i技术分享+bt技术分享j技术分享技术分享, 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 (2≤n≤5×10技术分享6技术分享), a (0≤|a|≤10技术分享6技术分享)技术分享 and b (0≤|b|≤10技术分享6技术分享)技术分享. The second line contains n技术分享 integers t技术分享1技术分享,t技术分享2技术分享,?,t技术分享n技术分享技术分享 where 0≤|t技术分享i技术分享|≤10技术分享6技术分享技术分享 for 1≤i≤n技术分享.

The sum of n技术分享 for all cases would not be larger than 5×10技术分享6技术分享技术分享.

Output
The output contains exactly T技术分享 lines.
For each test case, you should output the maximum value of at技术分享2技术分享i技术分享+bt技术分享j技术分享技术分享.

Sample Input
2 3 2 1 1 2 3 5 -1 0 -3 -3 0 3 3

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

Source

题意:求a*t1*t1+b*t2的值最大。
分析:数据不大,可以直接暴力求解,详解见代码。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
const double eps = 1e-6;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;
#define ll long long
#define CL(a) memset(a,0,sizeof(a))

ll T,n,a,b;
ll t[1000010];
ll min1,min2,max1,max2,k;//分别存最小的数、第二小的数、最大的数、第二大的数和最接近0的数

int main ()
{
    scanf ("%lld",&T);
    for (int cas=1; cas<=T; cas++)
    {
        scanf ("%lld%lld%lld",&n,&a,&b);
        k=INF;
        for (int i=0; i<n; i++)
        {
            scanf ("%lld",&t[i]);
        }
        cout<<"Case #"<<cas<<": ";
        sort(t, t+n);
        for (int i=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];//找出这五个数
        if (a<0&&b<0)//然后就是苦逼的找最大解了,注意负数的平方为正数
        {
            printf ("%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));
        }
        else printf ("0\n");
    }
    return 0;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

hdu5461 Largest Point(沈阳网赛)

标签:水   网络赛   

原文地址:http://blog.csdn.net/d_x_d/article/details/48597077

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!