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. 深入浅出JVM

    这篇文章简要解析了JVM的内部结构.下面这幅图展示了一个典型的JVM(符合JVM Specification Java SE 7 Edition)所具备的关键内部组件. 上图展示的所有这些组件都将在下 ...

  2. jdk自带的ThreadLocal和netty扩展的FastThreadLocal比较总结

    最近在分析一潜在内存泄露问题的时候,jmap出来中有很多的FastThreadLocalThread实例,看了下javadoc,如下: A special variant of ThreadLocal ...

  3. centos+Jenkins+maven搭建持续集成

    Jenkins是一个开源软件项目,旨在提供一个开放易用的软件平台,使软件的持续集成变成可能 什么是持续集成 随着软件开发复杂度的不断提高,团队开发成员间如何更好地协同工作以确保软件开发的质量已经慢慢成 ...

  4. 初步实现GoQtTemplate

    #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> //新添加 #include <opencv2/co ...

  5. Python3基础 set 删除list中的重复项

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

  6. 分页器的js实现代码 bootstrap Paginator.js

    参考: http://www.jb51.net/article/76093.htm 如前所述, 不要什么都想到 jquery的 脚本js, 应该首先推荐的是 css 和 元素本身的事件 函数 如: o ...

  7. 动态规划模板2|LCS最长公共子序列

    LCS最长公共子序列 模板代码: #include <iostream> #include <string.h> #include <string> using n ...

  8. BZOJ5131: [CodePlus2017年12月]可做题2

    BZOJ没有题面,差评 洛谷的题目链接 题解 其实这题很久之前就写了,也想写个题解但是太懒了,咕到了今天 在typora写完题解不想copy过来再改格式了,于是直接贴截图qwq #include &l ...

  9. 从nodejs到在线商城

    nodejs安装express开发框架 (开发环境:mkdir nodeshop && cd nodeshop > npm init > npm install expre ...

  10. xtu 1242 Yada Number 打表

    Yada Number       Time Limit : 2000 MS   Memory Limit : 65536 KB   Yada Number Problem Description: ...