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. webstrom 常用快捷键

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

  2. select函数详解及应用

    Select在Socket编程中还是比较重要的,可是对于初学Socket的人来说都不太爱用Select写程序,他们只是习惯写诸如connect. accept.recv或recvfrom这样的阻塞程序 ...

  3. Delphi SysErrorMessage 函数和系统错误信息表

    在看 API 文档时, 我们经常见到 GetLastError; 它可以返回操作后系统给的提示. 但 GetLastError 返回的只是一个信息代码, 如何返回对应的具体信息呢? FormatMes ...

  4. 网易云课堂_程序设计入门-C语言_第六章:数组_2鞍点

    2 鞍点(5分) 题目内容: 给定一个n*n矩阵A.矩阵A的鞍点是一个位置(i,j),在该位置上的元素是第i行上的最大数,第j列上的最小数.一个矩阵A也可能没有鞍点. 你的任务是找出A的鞍点. 输入格 ...

  5. 还是log4net的使用

    最近做个项目要用到日志系统,这这可把我给难住了,后来问了下度娘,发现只有你想不到的,没有那些找不到的开源组件,后来发现了log4net,但是我是控制台程序,没有个实例还真不好搞,想想还是看看他的运行过 ...

  6. CSS3 简易照片墙

    代码 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title& ...

  7. webview的配置

    WebSettings的常用方法介绍 WebSettings 通过webview获得WebSettings 调用WebSettings 的方法,配置webview WebSettings webSet ...

  8. C#自定义字符串替换Replace方法

    前一阵遇到一个如标题的算法题,是将原有字符串的某些片段替换成指定的新字符串片段,例如将源字符串:abcdeabcdfbcdefg中的cde替换成12345,得到结果字符串:ab12345abcdfb1 ...

  9. 相比于python2.6,python3.0的新特性。

    这篇文章主要介绍了相比于python2.6,python3.0的新特性.更详细的介绍请参见python3.0的文档. Common Stumbling Blocks 本段简单的列出容易使人出错的变动. ...

  10. Java 基本日期类使用(一)

    一.java.util.Date Date表示特定的瞬间,精确到毫秒,其子类有Date.Time.Timestap.默认情况下输出的Date对象为:Mon Oct 13 17:48:47 CST 20 ...