HDU5461 Largest Point 思维 2015沈阳icpc
Largest Point
Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 3065 Accepted Submission(s): 1078
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.
For each test case, you should output the maximum value of at2i+btj.
3 2 1
1 2 3
5 -1 0
-3 -3 0 3 3
Case #2: 0
#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的更多相关文章
- HDU 5451 Best Solver 数论 快速幂 2015沈阳icpc
Best Solver Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 65535/102400 K (Java/Others)Tota ...
- Largest Point (2015沈阳赛区网络赛水题)
Problem Description Given the sequence A with n integers t1,t2,⋯,tn. Given the integral coefficients ...
- 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 ...
- (并查集)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 ...
- (二叉树)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) ...
- 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 ...
- 记2017沈阳ICPC
2017沈阳ICPC 10月20日 早上十点抵达沈阳,趁着老师还没到,跑去故宫游玩了一下,玩到一点多回到宾馆,顺便吃了群里大佬说很好吃的喜家德虾饺(真的好好吃),回到宾馆后身体有点不舒服了,头晕晕的, ...
- Minimum Cut(2015沈阳online)【贪心】
Minimum Cut[贪心]2015沈阳online 题意:割最少的边使得图不连通,并且割掉的边中有且仅有一条是生成树的边. 首先,我们选择一条树中的边进行切割,此时仅考虑树上的边集,有两种情况:1 ...
- hdu5461 Largest Point(沈阳网赛)
Largest Point Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total ...
随机推荐
- java8中用流收集数据
用流收集数据 汇总 long howManyDishes = menu.stream().collect(Collectors.counting()); int totalCalories = men ...
- 重入锁的学习 (ReentrantLock)
重入锁 :(ReentrantLock) 上锁 用reentrantLock.lock 方法 解锁 用reentrantLock.unlock 方法 上锁和解锁 必须配对 可以多重上锁 Reentr ...
- 让 CXK 来教你实现游戏中的帧动画(上)
一款游戏除了基本功能之外,还需要给玩家更多视觉上的刺激,这个时候就需要用特效来装饰.本文就将介绍 Cocos Creator 的动画系统,除了标准的位移.旋转.缩放动画和序列帧动画以外,这套动画系统还 ...
- selenium操作cookies实现免密登录,自动发微博
一直想用selenium实现个小功能,比如发微博之类的,但是有的网站在登录会有验证码,没想到太好的方法解决,于是想到利用cookies来登录网站 第一步:获取一个可用的cookies,获取的cooki ...
- Java学习多线程第二天
内容介绍 线程安全 线程同步 死锁 Lock锁 等待唤醒机制 1 多线程 1.1 线程安全 如果有多个线程在同时运行,而这些线程可能会同时运行这段代码.程序每次运行结果和单线程运行的结果 ...
- CSS等分布局方法
原文链接:http://caibaojian.com/css-equal-layout.html CSS等比例划分,在CSS布局中是比较重要的,下面分享几种常用方法和探讨一下兼容性. 一:浮动布局+百 ...
- 笑谈CSS的伪元素
今晚上我们来简单的聊一聊CSS的伪元素,多说无益,开聊 GG: 话说盘古开天辟地之时. QQ:嗨,咱今天还能讲的完吗?您给来点实际的啊. GG:要听实际的是吧,得嘞,那今天咱就来聊一聊CSS里的伪元素 ...
- -bash: redis: command not found
在linux中安装redis,先是拉过去安装,然后通过命令:make 进行编译 编译完成以后通过命令 make install 完成安装:结果在进行启动linux的时候执行 ...
- ASP.NET Core MVC 之区域(Area)
区域(Area)是一个 ASP.NET MVC 功能,用于将相关功能组织为一个单独的命名空间(用于路由)和文件结构(用于视图).使用区域通过向控制器和操作添加 一个路由参数(area)来创建用于路由目 ...
- Linux - 通过expect工具实现脚本的自动交互
目录 1 安装expect工具 2 expect的常用命令 3 作用原理简介 3.1 示例脚本 3.2 脚本功能解读 4 其他脚本使用示例 4.1 直接通过expect执行多条命令 4.2 通过she ...