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. 数据结构-B树

      1.前言: 动态查找树主要有:二叉查找树(Binary Search Tree),平衡二叉查找树(Balanced Binary Search Tree),红黑树(Red-Black Tree ) ...

  2. linux如何ARP嗅探 Linux下嗅探工具Dsniff安装记录

      先来下载依赖包 和一些必须要用到的工具 我这里用的是 dsniff-2.3 的版本 wget http://www.monkey.org/~dugsong/dsniff/dsniff-2.3.ta ...

  3. Spring中常用的hql查询方法(getHibernateTemplate())

    一.find(String queryString); 示例:getHibernateTemplate().find("from bean.User"); 返回所有User对象 二 ...

  4. J2SE知识点摘记(一)

    1.        数组的声明时无法指定数组的长度. 2.        一维数组的声明和内存的分配 "数据类型    数组名[]; //声明一维数组     数组名=  new 数据类型[ ...

  5. PMC

    PMC = Production Material Control 生产及物料控制,通常分为两个部分: PC:生产控制或生产管制(台.日资公司俗称手配)主要职能是生产的计划与生产的进度控制 : MC: ...

  6. SPFA,dijskra,prime,topu四种算法的模板

    ////#include<stdio.h> ////#include<string.h> ////#include<queue> ////#include<a ...

  7. ASP.NET MVC4 json序列化器

    ASP.NET MVC4中调用WEB API的四个方法 2012年06月07日00:05 it168网站原创 作者:廖煜嵘 编辑:景保玉 我要评论(0) [IT168技术]当今的软件开发中,设计软件的 ...

  8. php什么是变量的数据类型

    什么是变量的数据类型 在变量中,由于变量占用的空间单元不一样(占的地盘大小不一样),也分成几种数据类型,就像超市商品的包装袋,有几种不同类型,不同的商品使用不同的包装袋.我们可以通过使用“memory ...

  9. 望大神批评教育国庆无聊之作:ObjectValidator

    起因: 本人国庆无聊,不知道干嘛, 所以模仿FluentValidation写了个简化版的ObjectValidator 个人设想是能用类似fluent的方式创建验证规则,然后使用者缓存并验证自己的对 ...

  10. PHP获取中文汉字首字母方法

    function getFirstLetter($str){ $fchar = ord($str{0}); if($fchar >= ord("A") and $fchar ...