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. Netfilter&iptables:如何理解连接跟踪机制?

    如何理解Netfilter中的连接跟踪机制? 本篇我打算以一个问句开头,因为在知识探索的道路上只有多问然后充分调动起思考的机器才能让自己走得更远.连接跟踪定义很简单:用来记录和跟踪连接的状态. 问:为 ...

  2. 谈谈javascript插件的写法

    插件顾名思义就是能在一个页面多处使用, 各自按自己的参数配置运行, 并且相互不会冲突. 会写javascript插件是进阶js高级的必经之路, 也是自己所学知识的一个典型的综合运用. 如果你还没头绪, ...

  3. CodeForces Round #287 Div.2

    A. Amr and Music (贪心) 水题,没能秒切,略尴尬. #include <cstdio> #include <algorithm> using namespac ...

  4. HNOI2008 GT 考试

    我不明白为什么是DP,我感觉和vijos的核电站问题(https://www.vijos.org/p/1232)差不多啊 这是别人的题解:http://www.cnblogs.com/Skywalke ...

  5. 【转】java枚举类型enum的使用

    原文网址:http://blog.csdn.net/wgw335363240/article/details/6359614 java 枚举类型enum 的使用 最近跟同事讨论问题的时候,突然同事提到 ...

  6. TortoiseSVN中分支和合并实践

    使用svn几年了,一直对分支和合并敬而远之,一来是因为分支的管理不该我操心,二来即使涉及到分支的管理,也不敢贸然使用合并功能,生怕合并出了问题对团队造成不良影响,最主要的原因是,自己对分支的目的和合并 ...

  7. DICOM医学图像处理:DIMSE消息发送与接收“大同小异”之DCMTK fo-dicom mDCM

    背景: 从DICOM网络传输一文开始,相继介绍了C-ECHO.C-FIND.C-STORE.C-MOVE等DIMSE-C服务的简单实现,博文中的代码给出的实例都是基于fo-dicom库来实现的,原因只 ...

  8. Spring 教程(二)

    一.Spring AOP介绍 开发其实就是在不断的重构,抽象重复代码,然后进行封装.从最原始的模块化编程到面向对象编程,代码的封装越来越整齐清晰,但是依然存在重复的代码,而这些重复代码几乎都是与业务逻 ...

  9. 单实例运行tz

    (引用了 Microsoft.VisualBasic.ApplicationServices)SingleInstanceApplicationWrapper.cs    using System.W ...

  10. iptables端口重定向

    需求:     tomcat容器使用普通用户启动不能开启1024以内端口,也就80端口不能使用.业务上通常使用80端口访问. 解决方法:     iptables既是防火墙也是带路由器功能.所以使用它 ...