题目描述

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  becomes the largest point.

输入

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 .

输出

The output contains exactly T lines. For each test case, you should output the maximum value of 

样例输入

2
3 2 1
1 2 3
5 -1 0
-3 -3 0 3 3

样例输出

Case #1: 20
Case #2: 0

题意:计算a*ti*ti+b*tj的最大值,且j != i

思路:分别计算a*t*t的值和b*t的值,并记录t的下标,比较两者最大值下标是否相等,不等直接输出结果,相等再比较次

最大值,输出结果。。。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef struct node
{ll step;//记录下标ll value;//记录值
}p;
p maxx[1000010],mbxx[1000010];//分别存a*t*t和b*t的值和下标
bool cmp(p a,p b)
{return a.value>b.value;
}
int main()
{int t;int temp=1;scanf("%d",&t);while(t--){ll n,a,b;scanf("%lld%lld%lld",&n,&a,&b);for(int i=0;i<n;i++){ll x;scanf("%lld",&x);maxx[i].step=i;maxx[i].value=a*x*x;mbxx[i].step=i;mbxx[i].value=b*x;}sort(maxx,maxx+n,cmp);sort(mbxx,mbxx+n,cmp);if(maxx[0].step!=mbxx[0].step)//判断最大值下标printf("Case #%d: %lld\n",temp++,maxx[0].value+mbxx[0].value);elseprintf("Case #%d: %lld\n",temp++,maxx[0].value+mbxx[1].value>maxx[1].value+mbxx[0].value?maxx[0].value+mbxx[1].value:maxx[1].value+mbxx[0].value);}return 0;
}

upc 8262: LARGEST POINT相关推荐

  1. poj 2559 Largest Rectangle in a Histogram 栈

    // poj 2559 Largest Rectangle in a Histogram 栈 // // n个矩形排在一块,不同的高度,让你求最大的矩形的面积(矩形紧挨在一起) // // 这道题用的 ...

  2. pat1094. The Largest Generation (25)

    1094. The Largest Generation (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...

  3. numpy使用np.argmax函数获取一维数组中最大值所在的索引(index of largest value in numpy array with np.argmax)

    numpy使用np.argmax函数获取一维数组中最大值所在的索引(index of largest value in numpy array with np.argmax) 目录 numpy使用np ...

  4. LeetCode 215. Kth Largest Element in an Array--数字第K大的元素--最大堆或优先队列--C++,Python解法

    题目地址:Kth Largest Element in an Array - LeetCode Find the kth largest element in an unsorted array. N ...

  5. LeetCode hard 84. Largest Rectangle in Histogram--python,java 15行,c++ 15行 解法

    题目地址: Given n non-negative integers representing the histogram's bar height where the width of each ...

  6. LintCode刷题——Largest Divisible Subset

    题目内容: Given a set of distinct positive integers, find the largest subset such that every pair (Si, S ...

  7. largest number java_将给定的数组组成最大的数 Largest Number

    问题: Given a list of non negative integers, arrange them such that they form the largest number. For ...

  8. UPC个人训练赛第十五场(AtCoder Grand Contest 031)

    传送门: [1]:AtCoder [2]:UPC比赛场 [3]:UPC补题场 参考资料 [1]:https://www.cnblogs.com/QLU-ACM/p/11191644.html B.Re ...

  9. Kth Largest Element in an Array

    Find the kth largest element in an unsorted array. Note that it is the kth largest element in the so ...

最新文章

  1. 第十六届全国大学智能车竞赛华南赛区成绩汇总
  2. 自己动手写C语言编译器(2)
  3. 面向对象——构造方法(重载)
  4. No operations allowed after connection closed--转
  5. 最值反演[PKUWC2018][loj2542]随机游走
  6. javascript 动态创建表格
  7. asp.net读取用户控件,自定义加载用户控件
  8. Linux系统编程30:进程信号之产生信号的四种方式(Core Dump,kill,raise)
  9. C语言 gcc 静态库
  10. Oracle迁移到MySQL性能下降的注意点
  11. 上架服务器必须做的准备工作
  12. wsdl2java生成客户端代码_利用wsdl2java工具生成webservice的客户端代码
  13. [WP8] Binding时,依照DataType来选择DataTemplate
  14. Apache与Tomcat集群配置
  15. 【离散数学】数理逻辑 第二章 谓词逻辑(3) 谓词公式的逻辑等价与蕴含、谓词演算的永真公式
  16. --set-gitd-purged参数解析
  17. 对话时人品牌咨询首席咨询官:有多少企业倒在了自己的品牌故事上?
  18. 1467 acm 矩阵不同行列的和
  19. asp.net 获得根文件夹在服务器上物理路径,asp.net获取网站目录物理路径示例
  20. npm run build:具体

热门文章

  1. Linux主机密码暴力破解
  2. 教会读者用高级iOS和macOS特性开发应用《Swift编程权威指南》(好书分享更新中)
  3. 第十五章 我国农业经济效益
  4. CADENAS赞助2019克罗地亚国际电动模型飞行大赛
  5. [歪谈]经理该不该写代码?
  6. 最终版宝宝取名程序,java版,我家宝宝名字已经确定。 HttpURLConnection
  7. Microsoft365和普通Office之间有什么区别 如何选择?
  8. 5min搭建SSM项目
  9. PHP根据身份证号码验证、获取星座、生肖和性别函数
  10. python中字符串的制表符是_在python中制表符是什么?