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 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
 
题目大意:给出一系列的数t,给出a、b,找出最大的a*ti2+b*tj,其中,i<>j。
题目分析:将a*ti2和b*tj分别存放在两个数组中,排下序并找出最大的。若两个最大的下标不相同,则和即为答案;若相同,再找两个次大的,求来自不同数组的最大的加次大的的和,再取二和之中大的便是答案。
 
 
代码如下:
# include<iostream>
# include<cstdio>
# include<cstring>
# include<vector>
# include<map>
# include<set>
# include<list>
# include<cstdlib>
# include<string>
# include<iomanip>
# include<algorithm>
using namespace std;
# define LL long double
struct arr
{
LL val;
int id;
arr(){}
arr(LL a,int b):val(a),id(b){}
bool operator < (const arr& a) const {
return val<a.val;
}
};
arr w1[500005],w2[500005];
int main()
{
int T,a,b,n,cas=0;
scanf("%d",&T);
while(T--)
{
int k;
scanf("%d%d%d",&n,&a,&b);
for(int i=0;i<n;++i){
scanf("%d",&k);
w1[i]=arr((LL)a*(LL)k*(LL)k,i);
w2[i]=arr((LL)b*(LL)k,i);
}
sort(w1,w1+n);
sort(w2,w2+n);
printf("Case #%d: ",++cas);
if(w1[n-1].id!=w2[n-1].id)
cout<<fixed<<setprecision(0)<<w1[n-1].val+w2[n-1].val<<endl;
else{
LL ans1=w1[n-1].val+w2[n-2].val;
LL ans2=w1[n-2].val+w2[n-1].val;
cout<<fixed<<setprecision(0)<<max(ans1,ans2)<<endl;
}
}
return 0;
}

  

 

Largest Point (2015沈阳赛区网络赛水题)的更多相关文章

  1. ACM-ICPC 2018 沈阳赛区(网络赛)

    D.Made In Heaven One day in the jail, F·F invites Jolyne Kujo (JOJO in brief) to play tennis with he ...

  2. HDU 5894 hannnnah_j’s Biological Test (组合数学) -2016 ICPC沈阳赛区网络赛

    题目链接 #include <map> #include <queue> #include <math.h> #include <stdio.h> #i ...

  3. HDU 5898 odd-even number (数位DP) -2016 ICPC沈阳赛区网络赛

    题目链接 题意:一个数字,它每个数位上的奇数都形成偶数长度的段,偶数位都形成奇数长度的段他就是好的.问[L , R]的好数个数. 题解:裸的数位dp, 从高到低考虑每个数位, 状态里存下到当前位为止的 ...

  4. HDU 5901 Count primes (1e11内的素数个数) -2016 ICPC沈阳赛区网络赛

    题目链接 题意:求[1,n]有多少个素数,1<=n<=10^11.时限为6000ms. 官方题解:一个模板题, 具体方法参考wiki或者Four Divisors. 题解:给出两种代码. ...

  5. hdu5443(2015长春赛区网络赛1007)暴力

    题意:给了一个数列,有多个询问,每个询问求某个区间内的最大值 数列长度 1000,询问个数 1000,静态,并不需要RMQ这些,直接暴力 n2 查找每个询问区间取最大值就行了. #include< ...

  6. hdu5442(2015长春赛区网络赛1006)后缀数组+KMP /最小表示法?

    题意:给定一个由小写字母组成的长度为 n 的字符串,首尾相连,可以从任意一个字符开始,顺时针或逆时针取这个串(长度为 n),求一个字典序最大的字符串的开始字符位置和顺时针或逆时针.如果有多个字典序最大 ...

  7. hdu5441(2015长春赛区网络赛1005)类最小生成树、并查集

    题意:有一张无向图,一些点之间有有权边,某条路径的值等于路径上所有边的边权的最大值,而某个点对的值为这两点间所有路径的值的最小值,给出多个询问,每个询问有一个值,询问有多少点对满足其值小于等于询问值. ...

  8. hdu5438(2015长春赛区网络赛1002)拓扑序+DFS

    题意:给出一张无向图,每个节点有各自的权值,问在点数为奇数的圈中的点的权值总和是多少. 通过拓扑序的做法标记出所有非圈上的点,做法就是加每条边的时候将两点的入度都加一,然后将所有度数为1的点入队,删去 ...

  9. ACM-ICPC 2015 沈阳赛区现场赛 I. Triple && HDU 5517(二维BIT)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5517 题意:有二元组(a,b),三元组(c,d,e).当b == e时它们能构成(a,c,d)然后,当 ...

随机推荐

  1. 50道JavaScript基础面试题(附答案)

    https://segmentfault.com/a/1190000015288700 1 介绍JavaScript的基本数据类型 Number.String .Boolean .Null.Undef ...

  2. Unity3D关于VR的Demo(一)

    https://blog.csdn.net/qq_15807167/article/details/52048998?locationNum=8&fps=1 阅读数:9716 最近有点忙,只有 ...

  3. SNMP学习笔记之iReasoning MIB Browser

    0x00 MIB Browser iReasoning MIB浏览器是一个强大和易于使用的工具由iReasoning SNMP API提供支持. MIB浏览器是工程师管理启用SNMP的网络设备和应用程 ...

  4. centos下nginx安装与配置

    nginx依赖以下模块: l  gzip模块需要 zlib 库 l  rewrite模块需要 pcre 库 l  ssl 功能需要openssl库 tar xzvf nginx-1.9.15.tar. ...

  5. Nodejs -- 使用koa2搭建数据爬虫

    当前爬虫项目开发所需中间件: cheerio: 则能够对请求结果进行解析,解析方式和jquery的解析方式几乎完全相同 cheerio中文文档 开发参考node - cheerio模块 superag ...

  6. Cocoa 初识

    1,判断程序是否第一次启动 OC: if (![[NSUserDefaults stringOfKeyInStandardDefaults:FirstOpenApp] boolValue]) { [s ...

  7. Python3基础 break while循环示例

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  8. mbr看图

  9. git commit如何修改默认编辑器为vim

    答:修改~/.gitconfig(修改这个文件将全局有效)或项目目录中的.git/config(修改此文件只是使当前项目默认使用vim)中增加以下内容: [core] editor=vim

  10. HDU 1796 How many integers can you find(容斥)题解

    思路:二进制解决容斥问题,就和昨天做的差不多.但是这里题目给的因子不是质因子,所以我们求多个因子相乘时要算最小公倍数.题目所给的因数为非负数,故可能有0,如果因子为0就要删除. 代码: #includ ...