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

给出t0-tn-1个数,和a,b,找出a*tx^2+b*ty的最大值,要求x!=y

这道题目数据有问题,根本没有500万个数,建一个50万的数组一样可以过

这里我们直接分别计算a*ti^2和b*ti,需要保持他们的序号,然后排序,去最大的两个,如果最大的两个序号相同,就

取     a*ti^2和b*ti分别第1大和第2大作比较,判断输出就可以了

AC:

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#define inf 9999999
#define maxn 5000007
using namespace std;int t,n,cas=1;
long long q;struct node
{long long x;int t;
}a[maxn],b[maxn];bool cmp(node x,node y)
{return x.x>y.x;
}int main()
{int cas=1,ai,bi;scanf("%d",&t);while(t--){scanf("%d%d%d",&n,&ai,&bi);for(int i=0;i<n;i++){scanf("%lld",&q);a[i].x=q*q*ai;a[i].t=i;b[i].x=q*bi;b[i].t=i;}printf("Case #%d: ",cas++);sort(a,a+n,cmp);sort(b,b+n,cmp);if(a[0].t!=b[0].t)printf("%lld\n",a[0].x+b[0].x);elseprintf("%lld\n",max((a[0].x+b[1].x),(a[1].x+b[0].x)));}return 0;
}

转载于:https://www.cnblogs.com/wangtao971115/p/10358312.html

hdu5461-Largest Point(贪心)相关推荐

  1. CodeForces - 946E Largest Beautiful Number(贪心+模拟)

    题目链接:点击查看 题目大意:给出一个数位长度为偶数的数字 n,需要求出一个比 n 小的,且所有数位重新排列后可以形成回文串,要求这个数字尽可能大 题目分析:从最低位开始贪心,依次枚举每一位的数字,然 ...

  2. 贪心问题JAVA_java背包问题(贪心法)

    完全背包问题 一个旅行者有一个最多能用m公斤的背包,现在有n种物品,每件的重量分别是W1,W2,...,Wn,每件的价值分别为C1,C2,...,Cn.若的每种物品的件数足够多.求旅行者能获得的最大总 ...

  3. Remove One Element(贪心)

    You are given an array aa consisting of nn integers. You can remove at most one element from this ar ...

  4. 笛卡尔树详解带建树模板及例题运用(Largest Submatrix of All 1’s,洗车 Myjnie,Removing Blocks,SPOJ PERIODNI)

    文章目录 笛卡尔树 介绍 例题 Largest Submatrix of All 1's 应用 「POI2015」洗车 Myjnie [AGC028B] Removing Blocks SPOJ PE ...

  5. 【CodeForces - 299C 】Weird Game (思维,模拟,贪心,博弈,OAE思想)

    题干: Yaroslav, Andrey and Roman can play cubes for hours and hours. But the game is for three, so whe ...

  6. codeforces#320(div2) D Or Game 贪心

    codeforces#320(div2) D  "Or" Game  贪心 D. "Or" Game time limit per test 2 seconds ...

  7. POJ 3154 Graveyard【多解,数论,贪心】

    Graveyard Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 1707   Accepted: 860   Specia ...

  8. 【BZOJ3048】Cow lineup,贪心+队列维护(或二分答案)

    传送门(权限题) 题面: 3048: [Usaco2013 Jan]Cow Lineup Time Limit: 2 Sec Memory Limit: 128 MB Submit: 121 Solv ...

  9. 【leetcode】1090. Largest Values From Labels

    题目如下: We have a set of items: the i-th item has value values[i] and label labels[i]. Then, we choose ...

  10. 求最大子数组(贪心算法)

    在<算法导论>中举了买股票和割铁棒的例子来说明动态规划和贪心算法的主体思想. 贪心算法:总是做出在当前看来最好的情况.(不是整体最优的) 1. 问题及答案 先抛出一个问题,类似于<算 ...

最新文章

  1. [Spring 深度解析]第7章 IoC容器的初始化过程
  2. UA MATH571A QE练习 R语言 非参数回归 上
  3. hdu5384(AC自动机+纪录重复单词出现的次数)
  4. 决策树基本原理与sklearn应用
  5. MySQL针对Swap分区的运维注意点
  6. Hyperset(排序+二分)
  7. c程序设计语言 hello,Hello, World!
  8. 笔记本vm系统的分辨率不好调整_苹果笔记本电脑怎么设置使用今声优盒
  9. 为什么你就是学不会 Numpy ? | 技术头条
  10. 【设计模式】之单例模式
  11. 如何在Mac上添加密码提示?
  12. 服务器msdtc没有安全显示项,MSDTC 疑难解答
  13. 星外主机系统被ZKEYS全资收购合并了
  14. 链家广州二手房的数据与分析——数据分析1
  15. Sql Server Report Builder 计算标准偏差
  16. android studio透明背景,使用Android Studio时出现黑色的PNG透明背景
  17. 简单了解下什么是中台?
  18. win10资源管理器窗口无法缩小
  19. 人工智能让你更美 来自美图影像实验室发布会实录
  20. 什么是JSONP协议 及对JSONP的改进

热门文章

  1. 深度操作系统 Deepin 20 BETA 发布
  2. sql数据表改为自动递增显示与其他表关联_MySQL萌新第一季 第四话-数据表的基本操作...
  3. 中国象棋将帅问题java_编程之美读书笔记1.2——中国象棋将帅问题
  4. Monte Carlo方法
  5. catboost特征重要性_一文讲解特征工程!经典外文PPT及中文解析
  6. asp实现注册登录界面_Win7系统登陆界面修改小技巧--win7w.com
  7. python 滚动条方法_Python OpenCV 使用滑动条来调整函数参数的方法
  8. python实现蒙特卡洛算法_用Python实现基于蒙特卡洛算法小实验
  9. python无法导入模块_python怎么导入模块
  10. ionic4 ts跳转传值 this.navController.navigateForward