Largest Point

Time Limit: 1 Sec

Memory Limit: 256 MB

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=5461

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 i≠j 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 (2≤n≤5×106), a (0≤|a|≤106) and b (0≤|b|≤106). The second line contains n integers t1,t2,⋯,tn where 0≤|ti|≤106 for 1≤i≤n.

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

HINT

题意

给你a,b,再给你n个数

然后让你求ati*ti+btj最大值是多少

题解:

我们是暴力做的,找到最大的两个数,最小的两个数,绝对值最大的两个数,绝对值最小的两个数

然后扔进一个vector里面,然后去重,然后暴力枚举的

但是还是怕tle,就分治了一下解法,数据小的话就直接n^2暴力枚举= =

代码:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <string>
#include <ctime>
#include <list>
#include <bitset>
typedef unsigned char byte;
#define pb push_back
#define input_fast std::ios::sync_with_stdio(false);std::cin.tie(0)
#define local freopen("in.txt","r",stdin)
#define pi acos(-1) using namespace std;
const int maxn = 5e6 + ;
long long a , b , ans , p[maxn];
int vis[] , used[maxn] , n , sz;
vector<long long>s; struct data
{
long long val;
int idx;
}; data A[maxn] , B[maxn]; bool cmp1(const data & x,const data & y)
{
return x.val < y.val;
} bool cmp2(const data & x,const data & y)
{
return abs(x.val) < abs(y.val);
} void initiation()
{
scanf("%d%I64d%I64d",&n,&a,&b);
memset(used,,sizeof(int)*(n+));
for(int i = ; i < n ; ++ i)
{
scanf("%I64d",&A[i].val);
A[i].idx = i;
B[i].val = A[i].val;
B[i].idx = i;
p[i] = A[i].val;
}
s.clear();
ans = -(1LL<<);
} void dfs(int cur , long long check)
{
if(cur == ) ans = max( ans , check);
else
{
for(int i = ; i < sz ; ++ i)
{
if(!vis[i])
{
vis[i] = ;
if(cur == ) dfs(cur + , check + a * s[i]*s[i] );
else dfs(cur + , check + b*s[i]);
vis[i] = ;
}
}
}
} long long solve()
{
sort(A,A+n,cmp1);
sort(B,B+n,cmp2);
used[A[].idx] = , used[A[].idx] = , used[A[n-].idx] = , used[A[n-].idx] = ;
used[B[].idx] = , used[B[].idx] = ; used[B[n-].idx] = , used[B[n-].idx] = ;
for(int i = ; i < n ; ++ i) if(used[i]) s.push_back(p[i]);
sz = s.size();
memset(vis,,sizeof(vis));
dfs(,);
return ans;
} long long solve2()
{
for(int i=;i<n;i++)
{
for(int j=;j<n;j++)
{
if(i==j) continue;
ans = max(ans,A[i].val*A[i].val*a+b*A[j].val);
}
}
return ans;
} int main(int argc,char *argv[])
{
int Case;
scanf("%d",&Case);
for(int cas = ; cas <= Case ; ++ cas)
{
initiation();
printf("Case #%d: ",cas);
if(n<=) printf("%I64d\n",solve2());
else printf("%I64d\n",solve());
}
return ;
}

hdu 5461 Largest Point 暴力的更多相关文章

  1. hdu 5461 Largest Point

    Thinking about it: 对于式子 a * ti * ti + b * tj,可以看作时有两部分构成 a * ti * ti 和 b * tj,如果整个式子要最大,则要求这两部分都要尽量大 ...

  2. hdu 5461(2015沈阳网赛 简单暴力) Largest Point

    题目;http://acm.hdu.edu.cn/showproblem.php?pid=5461 题意就是在数组中找出a*t[i]*t[i]+b*t[j]的最大值,特别注意的是这里i和i不能相等,想 ...

  3. HDU 5461:Largest Point

    Largest Point Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) To ...

  4. hdoj 5461 Largest Point

    Largest Point Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Tot ...

  5. HDU 1506 Largest Rectangle in a Histogram (dp左右处理边界的矩形问题)

    E - Largest Rectangle in a Histogram Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format: ...

  6. HDU 1506 Largest Rectangle in a Histogram set+二分

    Largest Rectangle in a Histogram Problem Description: A histogram is a polygon composed of a sequenc ...

  7. hdu 5762 Teacher Bo 暴力

    Teacher Bo 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5762 Description Teacher BoBo is a geogra ...

  8. HDU 1333 基础数论 暴力

    定义一种数位simth数,该数的各位之和等于其所有质因子所有位数字之和,现给出n求大于n的最小该种数,n最大不超过8位,那么直接暴力就可以了. /** @Date : 2017-09-08 14:12 ...

  9. HDU 4618 Palindrome Sub-Array 暴力

    Palindrome Sub-Array 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=4618 Description A palindrome s ...

随机推荐

  1. 武汉北大青鸟解读2016年10大IT热门岗位

    武汉北大青鸟解读2016年10大IT热门岗位 2016年1月5日 13:37 北大青鸟 这是IT从业者的辉煌时代,IT行业的失业率正处在历史的低点,而且有的岗位——例如网络和安全工程师以及软件开发人员 ...

  2. MediaPlayer和AudioTrack播放Audio的区别与联系

    转自http://blog.csdn.net/ameyume/article/details/7618820 播放声音可以用MediaPlayer和AudioTrack,两者都提供了java API供 ...

  3. hdu 4502 吉哥系列故事——临时工计划(dp)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=4502 思路:一个简单的dp ,比赛时没做出来呢..... d[i]代表 到第i天时的最大值 #includ ...

  4. poj 1080 Human Gene Functions(dp)

    题目:http://poj.org/problem?id=1080 题意:比较两个基因序列,测定它们的相似度,将两个基因排成直线,如果需要的话插入空格,使基因的长度相等,然后根据那个表格计算出相似度. ...

  5. poj 1840 Eqs (hash)

    题目:http://poj.org/problem?id=1840 题解:http://blog.csdn.net/lyy289065406/article/details/6647387 小优姐讲的 ...

  6. bzoj3170

    以前写的,好像忘写解题报告 注意是一个跟曼哈顿距离很有用的结论 |xi-xj|+|yi-yj|=max(|xi+yi-(xj+yj)|,|xi-yi+(xj-yj)|) 因为绝对值有个性质是|a-b| ...

  7. android listview 使用checkbox问题

    在android中使用listview时需要了解listview加载数据的原理,为了避免listview由于列表项过多每次需要进行new造成性能低下的问题,android中的listview使用了控件 ...

  8. SharePoint 2010 使用自定义aspx页面替换列表默认的新建(NewForm.aspx),查看(DispForm.aspx)和编辑(EditForm.aspx)页面

    转:http://www.cnblogs.com/sygwin/archive/2011/11/04/2236678.html 如何使用自定义的aspx页(比如Application Page)替换列 ...

  9. lightoj 1016

    水题,排个序直接搞. #include<cstdio> #include<string> #include<cstring> #include<iostrea ...

  10. Mongo DB 安装-及分布式集群部署(初稿)

    一.安装步骤, 1, 下载最新的Mongo DB数据库:http://www.mongodb.org/downloads?_ga=1.44426535.2020731121.1421844747\ 下 ...