HDU 5461 2015沈阳网络赛 Largest Point (暴力)

Largest Point

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

Problem Description
Given the sequence A with n integers t1,t2,,tn . Given the integral coefficients a and b . The fact that select two elements ti and tj of A and ij to maximize the value of at2i+btj , 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 (2n5×106), a (0|a|106) and b (0|b|106) . The second line contains n integers t1,t2,,tn where 0|ti|106 for 1in .
The sum of n for all cases would not be larger than 5×106 .
Output
The output contains exactly T lines.
For each test case, you should output the maximum value of at2i+btj .
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
Recommend
wange2014   |   We have carefully selected several similar problems for you:  5871 5870 5868 5867 5866 

题解:嘿嘿嘿。。。暴力居然过了。可能数据有点水吧。。。

AC代码:
#pragma comment(linker, "/STACK:102400000,102400000")
//#include<bits/stdc++.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <bitset>
#include <iomanip>
#include <list>
#include <stack>
#include <utility> 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
const double eps = 1e-8;  
const int INF = 1e9+7; 
const ll inf =(1LL<<62) ;
const int MOD = 1e9 + 7;  
const ll mod = (1LL<<32);
const int N =1e6+6; 
const int M=100010;
const int maxn=1001;
#define mst(a) memset(a, 0, sizeof(a))
#define M_P(x,y) make_pair(x,y)
#define pi acos(-1.0)
#define in freopen("in.txt","r",stdin) 
#define rep(i,j,k) for (int i = j; i <= k; i++)  
#define per(i,j,k) for (int i = j; i >= k; i--)  
#define lson x << 1, l, mid  
#define rson x << 1 | 1, mid + 1, r  
const int lowbit(int x) { return x&-x; }
//const int lowbit(int x) { return ((x)&((x)^((x)-1))); } 
int read(){ int v = 0, f = 1;char c =getchar();
while( c < 48 || 57 < c ){if(c=='-') f = -1;c = getchar();}
while(48 <= c && c <= 57) v = v*10+c-48, c = getchar();
return v*f;}
ll a[5000001];
int main()
{
	ll n,c,b;
    ll t,m,i,pos;
	ll num1,num2;
    while (~scanf("%I64d",&t))
    {
        	ll ans=1;
        	while (t--)
	 	{
        	scanf("%I64d %I64d %I64d",&n,&c,&b);
        	m=100000000;
        	for (i=1;i<=n;i++)scanf("%I64d",&a[i]);
        	sort(a+1,a+n+1);
        	for (i=1;i<=n;i++)
        	{
        		if (fabs(a[i])<m){
        			m=fabs(a[i]),pos=i;
				}
			}
            
       	 printf("Case #%I64d: ",ans++);
        	if (c<0&&b<0)
        	{
            	if (pos!=1) printf("%I64d\n",c*a[pos]*a[pos]+b*a[1]);
            	else
            	{
               		num1=c*a[1]*a[1]+b*a[2];
               		num2=c*a[2]*a[2]+b*a[1];
                	printf("%d\n",max(num1,num2));
            	}
            	continue;
        	}
        	else if (c>0&&b>0)
        	{
           		printf ("%I64d\n",max(max(c*a[n]*a[n]+b*a[n-1], c*a[n-1]*a[n-1]+b*a[n]), c*a[1]*a[1]+b*a[n]));
            	continue;
        	}
        	else if (c>=0&&b<=0)
        	{
            	printf ("%I64d\n",max(max(c*a[n]*a[n]+b*a[1], c*a[1]*a[1]+b*a[2]), c*a[2]*a[2]+b*a[1]));
            	continue;
        	}
        	else if (c<=0&&b>=0)
        	{
            	if (pos!=n) printf("%I64d\n",c*a[pos]*a[pos]+b*a[n]);
            	else
            	{
                	num1=c*a[n]*a[n]+b*a[n-1];
                	num2=c*a[n-1]*a[n-1]+b*a[n];
                	printf("%d\n",max(num1,num2));
            	}
            	continue;
        	}
     	}
    }
    return 0;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值