HDU 5461:Largest Point
Largest Point
Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 1102 Accepted Submission(s): 429
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.
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 nintegers 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.
For each test case, you should output the maximum value of at2i+btj.
2 3 2 1
1 2 3 5 -1 0
-3 -3 0 3 3
Case #1: 20
Case #2: 0
题意给了a b的两个值,然后给了一大堆t的值,问在这些t的值里面求最大的 at2i+btj.
分情况讨论,对于a大于零小于零,b大于零小于零。然后记录最大值 次大值 最小值 次小值 还有一个绝对值最小值,这五个值就够用了。
代码:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#pragma warning(disable:4996)
using namespace std; long long test, n, a, b;
long long i, j;
long long abs_min, max1, max2, min1, min2; int main()
{ long long temp;
cin >> test;
for (i = 1; i <= test; i++)
{
abs_min = 1000005;
max1 = -1000005;
max2 = -1000005;
min1 = 1000005;
min2 = 1000005; cin >> n >> a >> b; for (j = 1; j <= n; j++)
{
scanf("%lld",&temp); if (abs(temp) < abs_min)
{
abs_min = abs(temp);
}
if (temp > max1)
{
max2 = max1;
max1 = temp;
}
else if (temp > max2)
{
max2 = temp;
} if (temp < min1)
{
min2 = min1;
min1 = temp;
}
else if (temp < min2)
{
min2 = temp;
}
}
long long res;
if (a >= 0 && b>=0)
{
res = a*max1* max1 + b*max2;
res = max(res, a*min1 * min1 + b*max1);
}
else if (a >= 0 && b <= 0)
{
res = a*max1 * max1 + b*min1;
res = max(res, a*min1 * min1 + b*min2);
}
else if (a <= 0 && b <= 0)
{
if (min1 == abs_min)
{
res = a*abs_min*abs_min + b*min2;
}
else
{
res = a*abs_min*abs_min + b*min1;
}
}
else
{
if (max1 == abs_min)
{
res = a*abs_min*abs_min + b*max2;
}
else
{
res = a*abs_min*abs_min + b*max1;
}
}
cout << "Case #"<<i<<": "<<res<< endl;
} return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
HDU 5461:Largest Point的更多相关文章
- LeetCode之“排序”:Largest Number
题目链接 题目要求: Given a list of non negative integers, arrange them such that they form the largest numbe ...
- HDU - 6409:没有兄弟的舞会(数学+思维)
链接:HDU - 6409:没有兄弟的舞会 题意: 题解: 求出最大的 l[i] 的最大值 L 和 r[i] 的最大值 R,那么 h 一定在 [L, R] 中.枚举每一个最大值,那么每一个区间的对于答 ...
- POJ 3321:Apple Tree + HDU 3887:Counting Offspring(DFS序+树状数组)
http://poj.org/problem?id=3321 http://acm.hdu.edu.cn/showproblem.php?pid=3887 POJ 3321: 题意:给出一棵根节点为1 ...
- hdu 5461 Largest Point 暴力
Largest Point Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...
- hdu 5461(2015沈阳网赛 简单暴力) Largest Point
题目;http://acm.hdu.edu.cn/showproblem.php?pid=5461 题意就是在数组中找出a*t[i]*t[i]+b*t[j]的最大值,特别注意的是这里i和i不能相等,想 ...
- hdu 5461 Largest Point
Thinking about it: 对于式子 a * ti * ti + b * tj,可以看作时有两部分构成 a * ti * ti 和 b * tj,如果整个式子要最大,则要求这两部分都要尽量大 ...
- HDU 5510:Bazinga(暴力KMP)
http://acm.hdu.edu.cn/showproblem.php?pid=5510 Bazinga Problem Description Ladies and gentlemen, p ...
- HDU 2732:Leapin' Lizards(最大流)
http://acm.hdu.edu.cn/showproblem.php?pid=2732 题意:给出两个地图,蜥蜴从一个柱子跳跃到另外一个地方,那么这个柱子就可能会坍塌,第一个地图是柱子可以容忍跳 ...
- HDU 4289:Control(最小割)
http://acm.hdu.edu.cn/showproblem.php?pid=4289 题意:有n个城市,m条无向边,小偷要从s点开始逃到d点,在每个城市安放监控的花费是sa[i],问最小花费可 ...
随机推荐
- 解决css中display:inline-block产生的空隙问题
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 浏览器之本地缓存存储 localStorage 和 sessionStorage的区别以及用法
区别: localStorage永久保存在浏览器 :sessionStorage在浏览器关闭之后存储的数据就会销毁 用法:两者用法差不多,但是取值有所不同 编辑页面逻辑代码为: 这是给 id=btn ...
- vue 移动端屏幕适配
https://github.com/evrone/postcss-px-to-viewport/blob/master/README_CN.md基本配置 // eslint-disable-next ...
- 仿有道词典App开发
最近在学习HCoder提供的仿有道词典App项目,该项目采用MUI为前端框架,服务端采用PHP,底层采用了H5+.
- body滚动时左侧菜单固定
var top = $(".nav-frame").offset().top $(document).scroll(function(){ if($(this).scrollTop ...
- 前端学习笔记系列一:9 js中数组的拷贝
拷贝分为浅拷贝和深拷贝,在JavaScript中能够实现这两种拷贝的方式也是多种多样.以下是一维数组实现深拷贝和浅拷贝的各种方式. 一.浅拷贝 1.赋值 赋值是最直接的一种浅拷贝. let arr3 ...
- fiddler抓取URL之过滤设置
Fiddler是强大的抓包工具,它的原理是以web代理服务器的形式进行工作的,使用的代理地址是:127.0.0.1,端口默认为8888,我们也可以通过设置进行修改. 只要是开启了fiddler,我们的 ...
- taro中自定义tabbar实现中间图标凸出效果
遇到的一个需求是在tabbar上有一个凸起的小图标, 但是微信自带的tabbar是没有这个效果的, 无奈,只能使用自定义tabbar,查找了多方文档后发现大多是原生小程序实现, 关于taro文档的少之 ...
- es678910语法糖
傲娇: 新es是js的进步,是编程的进步,es6已经过去了5年了,兼容率达到了90%,还是有10%的手机不兼容,那到底应不应该去照顾那些跟不上的人,我觉得是不应该的,新es能5行写出来的功能,我为什么 ...
- [题解] LuoguP5666 树的重心
这个题......确实是CSPNOIP题qwq 感觉猜到一个性质就差不多了,首先,对于一棵树,随便拎一个节点\(rt\)当根节点,那么他的重心一定在\(rt\)的重儿子里,进一步的,可以发现重心一定在 ...