博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Largest Point
阅读量:7191 次
发布时间:2019-06-29

本文共 2085 字,大约阅读时间需要 6 分钟。

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 nintegers 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
#include 
#include
#include
#include
#include
#include
#include
using namespace std;const int oo = 1e9;const int N = 5*1e6+8;const int M = 6000;typedef long long LL;int ac[N], n;LL ans;struct da{ int num, id;} as[N];int cmp1(da a, da b){ return a.num < b.num;}int cmp2(da a, da b){ return abs(a.num) < abs(b.num);}int main(){ int i, T, a, b, A1, A2, B1, B2, ma, mb, xx=1; LL sum; scanf("%d", &T); while(T--) { scanf("%d %d %d", &n, &a, &b); for(i = 0; i < n; i++) { scanf("%d", &as[i].num); as[i].id = i; } A1 = A2 = B1 = B2 = 0; sort(as, as+n, cmp2); if(a >= 0) A1 = as[n-1].num, A2 = as[n-1].id, ma = as[n-2].num; ///A1 A2保存最大的绝对值以及下标 ma次大绝对值 else A1 = as[0].num, A2 = as[0].id, ma = as[1].num;/// A1 A2 保存最小绝对值及下标 ma次小绝对值 sort(as, as+n, cmp1); if(b >= 0) B1 = as[n-1].num, B2 = as[n-1].id, mb = as[n-2].num;///B1 B2最大的数及下标 mb次大的数 else B1 = as[0].num, B2 = as[0].id, mb = as[1].num;///B1 B2 最小的数及下标 mb 次小的数 if(A2 != B2)///这2个数不是同一个数 { ans = (LL)a*A1*A1; ans += (LL)b*B1; } else { ans = (LL)a*A1*A1; ans += (LL)b*mb; sum = (LL)a*ma*ma; sum += (LL)b*B1; ans = max(ans, sum); } printf("Case #%d: %I64d\n", xx++, ans); } return 0;}

  

转载于:https://www.cnblogs.com/PersistFaith/p/4821904.html

你可能感兴趣的文章
正则表达式
查看>>
MYSQL常用操作及python操作MYSQL常用类
查看>>
职场日记2-上班第一天
查看>>
技术人如何才不至于虚度一生?
查看>>
linux下文件的复制、移动与删除
查看>>
logo
查看>>
你属于开源性格测试六大分类中的哪一类呢
查看>>
MyBatis学习总结(15)——定制Mybatis自动代码生成的maven插件
查看>>
图形学国际学术会议及期刊收集
查看>>
你必须知道的ADO.NET(五) 细说数据库连接池
查看>>
ASP.NET使用ConfigurationSection在Web.Config创建自定义配置节集合
查看>>
给ubuntu系统的root设置密码:
查看>>
linux下nginx配置https(cent os 7.3)
查看>>
python获取系统时间
查看>>
frame与bounds的区别比较
查看>>
<正则吃饺子> :关于使用pd创建表时需要注意的地方
查看>>
Python输入和输出
查看>>
GIL(全局解释器锁)
查看>>
sqlserver 计算数据库时间差
查看>>
SQL 存储过程使用
查看>>