Largest Point

Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 3065    Accepted Submission(s): 1078

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
 
Source
 
 
题意:
  求a*ti*ti+b*tj的最大值,ti,tj是num数组里的两个数
分析:
  分情况考虑a和b为正为负的情况,当a,b为正时ti,tj要尽量大,因为a*ti*ti的影响大于b*tj,所以ti优先取最大值,在ti取完最大值后tj再来取剩下的最大值(这里用个map判断是否还剩余最大值,最大值可能有多个或者ti取了负的最大值)
  然后是为负的情况用同样的方法计算就行
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
#define debug(a) cout << #a << " " << a << endl
#define inf 0x17a6e6736e9
using namespace std;
const int maxn = 5*1e6 + 10;
const int mod = 1e9 + 7;
typedef long long ll;
ll s1[maxn], s2[maxn];
int main() {
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
ll T, t = 0;
cin >> T;
while( T -- ) {
t ++;
ll n, a, b;
cin >> n >> a >> b;
map<ll,ll> mp;
for( ll i = 0; i < n; i ++ ) {
cin >> s1[i];
s2[i] = abs(s1[i]);
mp[s1[i]] ++;
}
sort( s2, s2+n );
sort( s1, s1+n );
ll sum = 0;
if( a > 0 ) {
sum += a*s2[n-1]*s2[n-1];
if( b > 0 ) {
if( mp[-s2[n-1]] ) {
mp[-s2[n-1]] --;
} else {
mp[s2[n-1]] --;
}
if( mp[s1[n-1]] > 0 ) {
sum += b*s1[n-1];
} else {
sum += b*s1[n-2];
}
} else if( b < 0 ) {
if( mp[s2[n-1]] ) {
mp[s2[n-1]] --;
} else {
mp[-s2[n-1]] --;
}
if( mp[s1[0]] > 0 ) {
sum += b*s1[0];
} else {
sum += b*s1[1];
}
}
} else if( a < 0 ) {
sum += a*s2[0]*s2[0];
if( b > 0 ) {
if( mp[-s2[0]] ) {
mp[-s2[0]] --;
} else {
mp[s2[0]] --;
}
if( mp[s1[n-1]] > 0 ) {
sum += b*s1[n-1];
} else {
sum += b*s1[n-2];
}
} else if( b < 0 ) {
if( mp[s2[0]] ) {
mp[s2[0]] --;
} else {
mp[-s2[0]] --;
}
if( mp[s1[0]] > 0 ) {
sum += b*s1[0];
} else {
sum += b*s1[1];
}
}
}
cout << "Case #" << t << ": " << sum << endl;
}
return 0;
}

  

HDU5461 Largest Point 思维 2015沈阳icpc的更多相关文章

  1. HDU 5451 Best Solver 数论 快速幂 2015沈阳icpc

    Best Solver Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 65535/102400 K (Java/Others)Tota ...

  2. Largest Point (2015沈阳赛区网络赛水题)

    Problem Description Given the sequence A with n integers t1,t2,⋯,tn. Given the integral coefficients ...

  3. hdu 5444 Elven Postman(二叉树)——2015 ACM/ICPC Asia Regional Changchun Online

    Problem Description Elves are very peculiar creatures. As we all know, they can live for a very long ...

  4. (并查集)Travel -- hdu -- 5441(2015 ACM/ICPC Asia Regional Changchun Online )

    http://acm.hdu.edu.cn/showproblem.php?pid=5441 Travel Time Limit: 1500/1000 MS (Java/Others)    Memo ...

  5. (二叉树)Elven Postman -- HDU -- 54444(2015 ACM/ICPC Asia Regional Changchun Online)

    http://acm.hdu.edu.cn/showproblem.php?pid=5444 Elven Postman Time Limit: 1500/1000 MS (Java/Others)  ...

  6. 2015 ACM/ICPC Asia Regional Changchun Online HDU 5444 Elven Postman【二叉排序树的建树和遍历查找】

    Elven Postman Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  7. 记2017沈阳ICPC

    2017沈阳ICPC 10月20日 早上十点抵达沈阳,趁着老师还没到,跑去故宫游玩了一下,玩到一点多回到宾馆,顺便吃了群里大佬说很好吃的喜家德虾饺(真的好好吃),回到宾馆后身体有点不舒服了,头晕晕的, ...

  8. Minimum Cut(2015沈阳online)【贪心】

    Minimum Cut[贪心]2015沈阳online 题意:割最少的边使得图不连通,并且割掉的边中有且仅有一条是生成树的边. 首先,我们选择一条树中的边进行切割,此时仅考虑树上的边集,有两种情况:1 ...

  9. hdu5461 Largest Point(沈阳网赛)

    Largest Point Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total ...

随机推荐

  1. unity3d立方体碰撞检测(c#代码实现)

    由于unity自带的碰撞组件特别耗费性能,网上的unity物体碰撞的c#代码实现比较少,没有适合的,只能自己写一个来用: using System; using System.Collections. ...

  2. 工业物联网网关在线探测之TraceRoute

    佰马工业物联网网关BMG500在线探测通常有Ping.DNS.TraceRoute三种技术方式,这三种方式的区别与联系是什么?本文着重介绍工业物联网网关在线探测的工作原理,以图文形式介绍无线网关在线探 ...

  3. Iterator-Java

    在Java中,Iterator的作用就是为了方便处理集合中的元素.例如获取和删除集合中的元素. 在JDK8,Iterator接口提供了如下方法: 迭代器Iterator最基本的两个方法是next()和 ...

  4. js 实现 联动

    使用jQuery实现联动效果 应用场景:收货地址 1.准备三个下拉框 <select class="changeArea" id='province'> <opt ...

  5. JDK的命令行工具系列 (一) jps、jstat

    概述 在我们进行故障定位和性能分析时, 可以使用Java Dump(也叫Dump文件)来帮助排查问题, 它记录了JVM运行期间的内存占用和线程执行等情况.其中Heap Dump文件是二进制格式, 它保 ...

  6. SQL和NoSQL的区别

    一.概念 SQL (Structured Query Language) 数据库,指关系型数据库.主要代表:SQL Server,Oracle,MySQL(开源),PostgreSQL(开源). No ...

  7. 0R电阻在PCB布线中对布线畅通的一个小妙用

    在PCB布线中,我们都会尽量节约板子空间,将元器件排布的紧密一些,难免会遇到布线不通的时候. 博主下面就来说一个关于0R电阻在PCB布线使之畅通的一个小妙用. 使用0R电阻前 假设我们这个TXD的线周 ...

  8. JavaScript循环出现的问题——用闭包来解决

    在for循环中,数组长度为3,我本来是想对每个循环的元素绑定一个点击事件的,结果点击后控制台输出全部为1. for (var i = 0; i < data.data.length; i++) ...

  9. 防止Web攻击,做好HTTP安全标头

    前言   下图是几年前一位女性在访谈会上提问Linus(Linux操作系统之父) 为什么英伟达显卡在Linux系统中兼容性这么差? Linus说他们曾经去和英伟达谈过关于显卡在Linux上兼容的问题, ...

  10. Redis总结(九)Linux环境如何安装redis

    以前总结Redis 的一些基本的安装和使用,由于是测试方便,直接用的window 版的reids,并没有讲redis在linux下的安装.今天就补一下Linux环境如何安装redis. 大家可以这这里 ...