Largest Point

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

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
题解:
ax2和bx分开考虑;
代码:
 #include<stdio.h>
#include<string.h>
#include<math.h>
#define MAX(x,y)(x>y?x:y)
#define F for(int i=0;i<n;i++)
const int MAXN=;
const int INF=0x3f3f3f3f;
int m[MAXN],vis[MAXN];
int main(){
int T;
int n,a,b,flot=;
scanf("%d",&T);
while(T--){
memset(vis,,sizeof(vis));
scanf("%d%d%d",&n,&a,&b);
long long sum=,x,k;//xΪlong long
F scanf("%d",m+i);
if(a>){
x=-INF;
F if(x<fabs(m[i]))x=fabs(m[i]),k=i;
vis[k]=;
sum+=a*x*x;
}
else if(a<){
x=INF;
F if(x>fabs(m[i]))x=fabs(m[i]),k=i;
vis[k]=;
sum+=a*x*x;
}
if(b>){
x=-INF;
F if(x<m[i]&&!vis[i])x=m[i],k=i;
vis[k]=;
sum+=b*x;
}
else if(b<){
x=INF;
F if(x>m[i]&&!vis[i])x=m[i],k=i;
vis[k]=;
sum+=b*x;
}
printf("Case #%d: %lld\n",++flot,sum);
}
return ;
}
/*#include<stdio.h>
#include<algorithm>
#include<math.h>
#define MAX(x,y)(x>y?x:y)
#define js(x,y)(a*x*x+b*y)
using namespace std;
const int MAXN=5000010;
const int INF=0x3f3f3f3f;
int m[MAXN],ml[MAXN];
int main(){
int T,a,b,n,t[5],ans;
scanf("%d",&T);
for(int i=1;i<=T;i++){
scanf("%d%d%d",&n,&a,&b);
for(int j=0;j<n;j++)scanf("%d",m+j),ml[j]=fabs(m[j]);
t[0]=*max_element(m,m+n);t[1]=*min_element(m,m+n);
*max_element(m,m+n)=-INF;
t[2]=*max_element(m,m+n);
*min_element(m,m+n)=INF;
*min_element(m,m+n)=INF;
t[3]=*min_element(m,m+n);
ans=-INF;
printf("%d %d %d %d\n",t[0],t[1],t[2],t[3]);
if(a>=0&&b>=0){
if(fabs(t[1])>=fabs(t[0]))
ans=js(t[1],t[0]);
else
ans=MAX(js(t[0],t[2]),js(t[2],t[0]));
}
else if(a>=0&&b<0){
if(fabs(t[0])>=fabs(t[1]))
ans=js(t[0],t[1]);
else
ans=MAX(js(t[1],t[3]),js(t[3],t[1]));
}
else{
int x=*min_element(ml,ml+n); }
printf("Case #%d: %d\n",i,ans);
}
return 0;
}*/

hdu5461 Largest Point(沈阳网赛)的更多相关文章

  1. 2019沈阳网赛树形dp

    https://nanti.jisuanke.com/t/41403 2019沈阳网络赛D题 树形dp.一棵树,求任意两个点的距离之和.u-v和v-u算两次.两点之间的距离分为三类,模3等于0,1,2 ...

  2. hdu 5461(2015沈阳网赛 简单暴力) Largest Point

    题目;http://acm.hdu.edu.cn/showproblem.php?pid=5461 题意就是在数组中找出a*t[i]*t[i]+b*t[j]的最大值,特别注意的是这里i和i不能相等,想 ...

  3. hdu 5455 (2015沈阳网赛 简单题) Fang Fang

    题目;http://acm.hdu.edu.cn/showproblem.php?pid=5455 题意就是找出所给字符串有多少个满足题目所给条件的子串,重复的也算,坑点是如果有c,f以外的字符也是不 ...

  4. hdu 5459(2015沈阳网赛) Jesus Is Here

    题目;http://acm.hdu.edu.cn/showproblem.php?pid=5459 题意 给出一组字符串,每个字符串都是前两个字符串相加而成,求第n个字符串的c的各个坐标的差的和,结果 ...

  5. 2018沈阳网赛F--上下界网络流

    建图: 首先加一个源点s和汇点t,分别连接在二分图的左边和右边,每条弧的上下界为[L, R],二分图左边和右边之间连弧上下界为[0,1],其实就相当于连弧为1. 然后问题就转换为:有源汇最大流. 继续 ...

  6. ACM学习历程—HDU 5459 Jesus Is Here(递推)(2015沈阳网赛1010题)

    Sample Input 9 5 6 7 8 113 1205 199312 199401 201314 Sample Output Case #1: 5 Case #2: 16 Case #3: 8 ...

  7. ACM学习历程—HDU 5451 Best Solver(Fibonacci数列 && 快速幂)(2015沈阳网赛1002题)

    Problem Description The so-called best problem solver can easily solve this problem, with his/her ch ...

  8. 2015年沈阳网赛 Jesus Is Here(DP中的计数问题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5459 题目描述:给定一个递推得来的字符串,问字符串中不同cff之间的距离之和, 递推规则: s1=c; ...

  9. 【转】HDU 6194 string string string (2017沈阳网赛-后缀数组)

    转自:http://blog.csdn.net/aozil_yang/article/details/77929216 题意: 告诉你一个字符串和k , 求这个字符串中有多少不同的子串恰好出现了k 次 ...

随机推荐

  1. 解决Eclipse下第三方库无法导航源代码

    写在前面(的废话):Eclipse无法导航代码,存在的可能性非常多,这里我们只讨论在引用第三方库时无法导航的情况,是一个很简单的Case,但是搜索能力好像不太及格,没找到一针见血的方案,于是自己研究了 ...

  2. webstrom 常用快捷键

    最近在学习javascript,同时发现了一款非常好用的IDE webstrom 现在记录改IDE的快捷键 1. ctrl + shift + n: 打开工程中的文件,目的是打开当前工程下任意目录的文 ...

  3. [问题解决]LaTex 进行中文文档操作

    第一步,在\documentclass后输入 \usepackage{fontspec, xunicode, xltxtra} \usepackage{xeCJK}%中文字体 \setCJKmainf ...

  4. PixelFormat 图像颜色的数据格式

    PixelFormat: (指定图像中每个像素的颜色数据的格式) Delphi                                        微软                    ...

  5. CC++初学者编程教程(7) 搭建Windows EclipseCCPP软件开发环境

    1根据电脑是32位还是64位来选择工具 2 查看电脑是64位 3 管理员身份运行这个文件 4 安装JDK64位 5. 下一步 6 开始安装 7 安装JAVA 8 安装进行时 9 安装成功 10解压缩 ...

  6. poj2924---高斯求和

    #include <stdio.h> #include <stdlib.h> int main() { ; long long ans,a,b; scanf("%d& ...

  7. ubuntu gnome vnc

    1,安装登陆管理器 --apt-get install gdm (还可以为kdm/xdm) lightdm,display manager

  8. 关于ztree打开关闭所有节点,选中指定id节点

    var isOneByOneExpand=false;//是否递归展开 //展开节点 function expendNode(nodeId){ var node = treeObj.getNodeBy ...

  9. Proud Merchants(01背包)

    Proud Merchants Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) To ...

  10. oracle 物化视图导入导出报错

    1.exp导出报EXP-00008: 遇到 ORACLE 错误 1455,ORA-01455: 转换列溢出整数数据类型 2.imp导入报.注: 表包括 ROWID 列, 其值可能已废弃,不是警告也不是 ...