Largest Point

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

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 nintegers 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

题意:在一个数组里找两个下标不一样的数,使at2i+btj最大,下标不一样,数值可能一样

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<math.h>
#include<algorithm> using namespace std; const int maxn = *1e6+;
#define INF 0x3f3f3f3f struct node
{
int x, id;
}P[maxn]; int cmp(node a, node b)
{
return abs(a.x) < abs(b.x);
} int cmp1(node a, node b)
{
return a.x < b.x;
} int main()
{
int t, n, a, b, l = ;
int A1, a1, ma, B1, b1, mb;
scanf("%d", &t);
long long sum, ans;
while(t--)
{
scanf("%d%d%d", &n, &a, &b);
for(int i = ; i < n; i++)
{
scanf("%d", &P[i].x);
P[i].id = i;
}
A1 = a1 = ma = B1 = b1 = mb = ;
sort(P, P+n, cmp);
if(a >= )
A1 = P[n-].x, a1 = P[n-].id, ma = P[n-].x;
else
A1 = P[].x, a1 = P[].id, ma = P[].x;
sort(P, P+n, cmp1);
if(b >= )
B1 = P[n-].x, b1 = P[n-].id, mb = P[n-].x;
else
B1 = P[].x, b1 = P[].id, mb = P[].x;
if(a1 != b1)
{
sum = (long long)a * A1 *A1;
sum += (long long)b * B1;
} else
{
sum = (long long)a * A1*A1;
sum += (long long)b*mb; // 为什么非得这么加,这么强制转换,orWA
ans = (long long)a*ma*ma;
ans += (long long)b*B1;
sum = sum > ans ? sum : ans;
}
printf("Case #%d: %I64d\n",l++, sum);
}
return ;
}

Largest Point的更多相关文章

  1. Java 特定规则排序-LeetCode 179 Largest Number

    Given a list of non negative integers, arrange them such that they form the largest number. For exam ...

  2. [LeetCode] Split Array Largest Sum 分割数组的最大值

    Given an array which consists of non-negative integers and an integer m, you can split the array int ...

  3. [LeetCode] Largest Divisible Subset 最大可整除的子集合

    Given a set of distinct positive integers, find the largest subset such that every pair (Si, Sj) of ...

  4. [LeetCode] Largest BST Subtree 最大的二分搜索子树

    Given a binary tree, find the largest subtree which is a Binary Search Tree (BST), where largest mea ...

  5. [LeetCode] Kth Largest Element in an Array 数组中第k大的数字

    Find the kth largest element in an unsorted array. Note that it is the kth largest element in the so ...

  6. [LeetCode] Largest Number 最大组合数

    Given a list of non negative integers, arrange them such that they form the largest number. For exam ...

  7. [LeetCode] Largest Rectangle in Histogram 直方图中最大的矩形

    Given n non-negative integers representing the histogram's bar height where the width of each bar is ...

  8. 【leetcode】Largest Number

    题目简述: Given a list of non negative integers, arrange them such that they form the largest number. Fo ...

  9. poj 2559 Largest Rectangle in a Histogram - 单调栈

    Largest Rectangle in a Histogram Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19782 ...

  10. POJ2985 The k-th Largest Group[树状数组求第k大值+并查集||treap+并查集]

    The k-th Largest Group Time Limit: 2000MS   Memory Limit: 131072K Total Submissions: 8807   Accepted ...

随机推荐

  1. Winform 开源控件库( Sheng.Winform.Controls)

    升讯威 .Net WinForm 控件库提供了超过15种 Winform 控件,你可以直接使用本控件库,更可以通过本控件库学到 Winform 控件开发的方法和理念. 你可以学习到: 如何基于 Con ...

  2. create-react-app 创建react应用环境变量(env)配置

    参考:https://facebook.github.io/create-react-app/docs/adding-custom-environment-variables What other . ...

  3. Charls

    1.连接设备 charles--proxy--proxy setting 设置端口号 charles--proxy--ssl proxy setting 设置代理域名 [pc端] charles--p ...

  4. Mac014--Sourcetree安装(Git client)

    Sourcetree:git client Tool Step1:download address: https://www.sourcetreeapp.com/ Step2:要求username/u ...

  5. linux文件io与标准io

    文件IO实际是API,Linux对文件操作主要流程为:打开(open),操作(write.read.lseek),关闭(close). 1.打开文件函数open(): 涉及的头文件:  #includ ...

  6. 通过总线机制实现自动刷新客户端配置(Consul,Spring Cloud Config,Spring Cloud Bus)

    通过总线机制实现自动刷新客户端配置 方案示意图 利用Git服务的webhook通知功能,在每次更新配置之后,Git服务器会用POST方式调用配置中心的/actuator/bus-refresh接口,配 ...

  7. 处理Chrome等浏览器无法上网,但QQ能正常使用问题

    常见于安装VPN软件后导致的问题: 问题描述:QQ.微信客户端.等聊天工具可以聊天,但不能使用浏览器:打开网页失败:网络连接正常 问题解决步骤: 策略1: 打开网络和共享中心>>> ...

  8. echart 属性设计大全

    // 全图默认背景  // backgroundColor: ‘rgba(0,0,0,0)’, // 默认色板 color: ['#ff7f50','#87cefa','#da70d6','#32cd ...

  9. append动态生成的元素,无法触发事件的原因及解决方案

    今天笔者在实现一个简单的动态生成元素功能的时候,发现了一个问题: 使用append动态生成的元素事件绑定失效了. 查阅资料后发现: click(fn)当选中的选择器被点击时触发回调函数fn.只针对与页 ...

  10. Hibernate初始化创建SessionFactory,Session,关闭SessonFactory,session

    1.hibernate.cfg.xml <?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE hibernate-configuratio ...