hdu 5461(分类讨论)
Largest Point
Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 1485 Accepted Submission(s): 588
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<stdio.h>
#include<iostream>
#include<string.h>
#include <stdlib.h>
#include<math.h>
#include<algorithm>
using namespace std;
typedef long long LL;
const LL INF = <<;
int main(){
int tcase;
scanf("%d",&tcase);
int t =;
while(tcase--){
int n,a,b;
scanf("%d%d%d",&n,&a,&b);
LL ans;
if(a>=&&b>=){
LL fmax = -INF,smax = -INF;
for(int i=;i<=n;i++){
LL num;
scanf("%lld",&num);
if(num>fmax){
smax = fmax;
fmax = num;
}else{
smax = max(smax,num);
}
}
ans = max(a*fmax*fmax+b*smax,a*smax*smax+b*fmax);
}else if(a>&&b<){
LL MAX=-INF,SMAX=-INF; ///平方的最大和次大
LL MIN=INF,SMIN=INF; ///最小和次小
int id1,id2;
for(int i=;i<=n;i++){
LL num;
scanf("%lld",&num);
LL temp = num*num;
if(num<MIN){
SMIN = MIN;
MIN = num;
id1 = i;
}else SMIN = min(SMIN,num);
if(temp>MAX){
SMAX = MAX;
MAX = temp;
id2 = i;
}else SMAX = max(SMAX,num);
}
if(id1!=id2){
ans = a*MAX+b*MIN;
}else{
ans = max(a*SMAX+b*MIN,a*MAX+b*SMIN);
}
}else if(a<&&b>){
LL MAX = -INF,MIN = INF; ///注意这里的最小是指平方的最小
LL smin=INF,smax = -INF; ///此处次小是指平方的次小
int id1,id2; ///分别记录ti 和 tj 的位置
for(int i=;i<=n;i++){
LL num;
scanf("%lld",&num);
if(num>MAX) {
smax = MAX;
MAX = num;
id1 = i;
}else smax = max(smax,num);
LL temp = num*num;
if(temp<MIN){
smin = MIN;
MIN = temp;
id2 = i;
}else smin = min(smin,temp);
}
if(id1!=id2){
ans = a*MIN+b*MAX;
}
else{
ans = max(a*MIN+b*smax,a*smin+b*MAX);
}
}else {
LL MIN = INF,SMIN = INF; ///这两个值代表绝对值次小和最小的平方
LL MIN1 = INF,SMIN1 = INF; ///这两个值代表次小和最小
int id1,id2;
for(int i=;i<=n;i++){
LL num;
scanf("%lld",&num);
LL temp = num*num;
if(num<MIN1) {
SMIN1 = MIN1;
MIN1 = num;
id1 = i;
}else SMIN1 = min(SMIN1,num); if(temp<MIN){
SMIN = MIN;
MIN = temp;
id2 = i;
}else SMIN = min(SMIN,temp);
}
if(id1!=id2){
ans = a*MIN+b*MIN1;
}else{
ans = max(a*MIN+b*SMIN1,a*SMIN+b*MIN1);
}
}
printf("Case #%d: %lld\n",t++,ans);
}
return ;
}
hdu 5461(分类讨论)的更多相关文章
- HDU 5203 Rikka with wood sticks 分类讨论
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5203 bc(chinese):http://bestcoder.hdu.edu.cn/con ...
- HDU 6627 equation (分类讨论)
2019 杭电多校 5 1004 题目链接:HDU 6627 比赛链接:2019 Multi-University Training Contest 5 Problem Description You ...
- HDU 6665 Calabash and Landlord (分类讨论)
2019 杭电多校 8 1009 题目链接:HDU 6665 比赛链接:2019 Multi-University Training Contest 8 Problem Description Cal ...
- HDU5957 Query on a graph(拓扑找环,BFS序,线段树更新,分类讨论)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5957 题意:D(u,v)是节点u和节点v之间的距离,S(u,v)是一系列满足D(u,x)<=k的点 ...
- Codeforces 460D Little Victor and Set --分类讨论+构造
题意:从区间[L,R]中选取不多于k个数,使这些数异或和尽量小,输出最小异或和以及选取的那些数. 解法:分类讨论. 设选取k个数. 1. k=4的时候如果区间长度>=4且L是偶数,那么可以构造四 ...
- BZOJ-1067 降雨量 线段树+分类讨论
这道B题,刚的不行,各种碎点及其容易忽略,受不鸟了直接 1067: [SCOI2007]降雨量 Time Limit: 1 Sec Memory Limit: 162 MB Submit: 2859 ...
- UVaLive 6862 Triples (数学+分类讨论)
题意:给定一个n和m,问你x^j + y^j = z^j 的数量有多少个,其中0 <= x <= y <= z <= m, j = 2, 3, 4, ... n. 析:是一个数 ...
- 枚举(分类讨论):BZOJ 1177: [Apio2009]Oil
1177: [Apio2009]Oil Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 1477 Solved: 589[Submit] Descri ...
- hdu 5461 Largest Point
Thinking about it: 对于式子 a * ti * ti + b * tj,可以看作时有两部分构成 a * ti * ti 和 b * tj,如果整个式子要最大,则要求这两部分都要尽量大 ...
随机推荐
- Keras预训练模型下载后保存路径
https://blog.csdn.net/xiaohuihui1994/article/details/83340080
- java--String、StringBuilder、StringBuffer的解析和比较?
一.String的解析 1.String的含义 ①String是不可以被继承的,String类是final类,String类是由char[]数组来存储字符串. ②String是不可变的字符序列,如果存 ...
- Spring Boot 应用 快速发布到linux服务器的脚本代码示例
前提说明:spring boot 应用打包成jar包之后要部署到Linux服务器上面运行,我用的nohup java -jar 命令,但是代码更新之后重新部署的时候覆盖原来的项目,又要手动运行ps - ...
- 万门大学Python零基础10天进阶班视频教程
点击了解更多Python课程>>> 万门大学Python零基础10天进阶班视频教程 课程简介: 旨在通过两周的学习,让学生不仅能掌握python编程基础从而进行计算机程序的开发, 还 ...
- 安装pymysql后,import pymysql,pycharm编辑器中报错
cmd 中运行 pip3 install PyMySQL 或者采用git git clone https://github.com/PyMySQL/PyMySQL cd PyMySQL/ python ...
- python多进程并发进程池Pool
简介: python中的多进程主要使用到 multiprocessing 这个库.低版本python这个库在使用 multiprocessing.Manager().Queue时会出问题,建议大家升级 ...
- Python入门学习笔记2:刷题
1) LeetCode 强的面试题和算法题,要求也比较高,很多国内外的码农在上面刷题.难度从easy到hard都有,而且覆盖面极广,需要你的综合实力去答题. 最简单的题比如字符串的处理有的时候也要用到 ...
- Linux学习-逻辑滚动条管理员 (Logical Volume Manager)
LVM 可以整合多个实体 partition 在一起, 让这些 partitions 看起来就像是一个磁盘一样!而且,还可以在未来新增或移除其他的实 体 partition 到这个 LVM 管理的磁盘 ...
- Http协议——基本概念
一.浏览网页的过程 用户输入一个url,浏览器根据url给web服务器发送一个Request,web服务器接收到Request后进行处理,并返回浏览器一个Response,可以响应一个静态页面或者图片 ...
- 小x的质数(线性O(n)筛素数)
小x的质数 题目描述 小 X 是一位热爱数学的男孩子,在茫茫的数字中,他对质数更有一种独特的情感.小 X 认为,质数是一切自然数起源的地方. 在小 X 的认知里,质数是除了本身和 11 以外,没有其他 ...