Largest Point

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

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了两道题。所以感觉要多做少错思路题。
这个题分4种情况考虑,每种又分为三种情况。举一个例子:
a>0,b<0时
那么ti^2尽可能的大,tj尽可能的小。如果i!=j 那么直接取ti^2最大与tj最小。
如果i==j 那么在ti^2次大与tj最小和ti^2最大与tj次小中取大者。
还有就是 INF不能这样赋值 ,如1<<40 ,这个地方WA了好多次,,他会变成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(分类讨论)的更多相关文章

  1. HDU 5203 Rikka with wood sticks 分类讨论

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5203 bc(chinese):http://bestcoder.hdu.edu.cn/con ...

  2. HDU 6627 equation (分类讨论)

    2019 杭电多校 5 1004 题目链接:HDU 6627 比赛链接:2019 Multi-University Training Contest 5 Problem Description You ...

  3. HDU 6665 Calabash and Landlord (分类讨论)

    2019 杭电多校 8 1009 题目链接:HDU 6665 比赛链接:2019 Multi-University Training Contest 8 Problem Description Cal ...

  4. 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的点 ...

  5. Codeforces 460D Little Victor and Set --分类讨论+构造

    题意:从区间[L,R]中选取不多于k个数,使这些数异或和尽量小,输出最小异或和以及选取的那些数. 解法:分类讨论. 设选取k个数. 1. k=4的时候如果区间长度>=4且L是偶数,那么可以构造四 ...

  6. BZOJ-1067 降雨量 线段树+分类讨论

    这道B题,刚的不行,各种碎点及其容易忽略,受不鸟了直接 1067: [SCOI2007]降雨量 Time Limit: 1 Sec Memory Limit: 162 MB Submit: 2859 ...

  7. UVaLive 6862 Triples (数学+分类讨论)

    题意:给定一个n和m,问你x^j + y^j = z^j 的数量有多少个,其中0 <= x <= y <= z <= m, j = 2, 3, 4, ... n. 析:是一个数 ...

  8. 枚举(分类讨论):BZOJ 1177: [Apio2009]Oil

    1177: [Apio2009]Oil Time Limit: 15 Sec  Memory Limit: 162 MBSubmit: 1477  Solved: 589[Submit] Descri ...

  9. hdu 5461 Largest Point

    Thinking about it: 对于式子 a * ti * ti + b * tj,可以看作时有两部分构成 a * ti * ti 和 b * tj,如果整个式子要最大,则要求这两部分都要尽量大 ...

随机推荐

  1. MySQL数据库---索引

    索引的作用就是快速找出在一个列上用一特定值的行.如果没有索引,MySQL不得不首先以第一条记录开始并然后读完整个表直到它找出相关的行. 索引的类型: 先写一个建表语句: CREATE TABLE `t ...

  2. Docker 容器的跨主机连接

    使用网桥实现跨主枳容器连接 不推荐 使用OpenvSwitch实现跨主机容器连接 OpenvSwitch: OpenvSwitch是一个高质量的.多层虚拟交换枳,使用开源Apache2.0许可协议,由 ...

  3. 配置基于Vim的Python开发环境

    配置基于Vim的Python开发环境插件 Vundle YouCompleteMe NERDTree Vim-Jinja2-Syntax set nocompatible " be iMpr ...

  4. october安装过程

    下载代码 composer create-project october/october myoctober 准备好数据库, create database october; 配置环境于安装 php ...

  5. mysql的字符串连接符

    以前用SQL Server 连接字符串是用“+”,现在数据库用mysql,写个累加两个字段值SQL语句居然不支持"+",郁闷了半天在网上查下,才知道mysql里的+是数字相加的操作 ...

  6. destoon ip接口失效修改 修改后偶尔会加载很慢

    因为百度ip转换增加了密匙验证,所以导致之前的接口无法再转换ip地址的信息,修复方法如下:打开include\cloud.func.php文件搜索: function iplookup($ip) { ...

  7. python面试题之什么是lambda函数?

    lambda表达式,通常是在需要一个函数,但是又不想费神去命名一个函数的场合下使用,也就是指匿名函数. lambda所表示的匿名函数的内容应该是很简单的,如果复杂的话,干脆就重新定义一个函数了,使用l ...

  8. Python9-进程池-day38

    复习 # 信号量 from multiprocessing import Semaphore # 用锁的原理实现的,内置了一个计数器 # 在同一个事件,只能有指定数量的进程执行某一段被控制住的代码 # ...

  9. jmeter jdbc各字段的含义

    JDBC采样器各选项的含义如下: 1.Variable Name 其中的Variable Name和上面JDBC Connection Configuration中的Variable Name相同,这 ...

  10. [uiautomator篇][exist 存在,但click错误]

    uiautomator定位页面元素是,定位存在的;但是click的时候,发现点的位置不对,(不知道是android系统的问题还是uiautomator的问题,初步怀疑是系统的问题)