Largest Point
Largest Point
Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 969 Accepted Submission(s): 384
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.
For each test case, you should output the maximum value of at2i+btj.
Case #2: 0
题意:在一个数组里找两个下标不一样的数,使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的更多相关文章
- Java 特定规则排序-LeetCode 179 Largest Number
Given a list of non negative integers, arrange them such that they form the largest number. For exam ...
- [LeetCode] Split Array Largest Sum 分割数组的最大值
Given an array which consists of non-negative integers and an integer m, you can split the array int ...
- [LeetCode] Largest Divisible Subset 最大可整除的子集合
Given a set of distinct positive integers, find the largest subset such that every pair (Si, Sj) of ...
- [LeetCode] Largest BST Subtree 最大的二分搜索子树
Given a binary tree, find the largest subtree which is a Binary Search Tree (BST), where largest mea ...
- [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 ...
- [LeetCode] Largest Number 最大组合数
Given a list of non negative integers, arrange them such that they form the largest number. For exam ...
- [LeetCode] Largest Rectangle in Histogram 直方图中最大的矩形
Given n non-negative integers representing the histogram's bar height where the width of each bar is ...
- 【leetcode】Largest Number
题目简述: Given a list of non negative integers, arrange them such that they form the largest number. Fo ...
- poj 2559 Largest Rectangle in a Histogram - 单调栈
Largest Rectangle in a Histogram Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19782 ...
- POJ2985 The k-th Largest Group[树状数组求第k大值+并查集||treap+并查集]
The k-th Largest Group Time Limit: 2000MS Memory Limit: 131072K Total Submissions: 8807 Accepted ...
随机推荐
- delphi开发实例:保存字体设置的方法
http://blog.csdn.net/delphi308/article/details/9906147 delphi开发实例:保存字体设置的方法 2013-08-11 22:37 446人阅读 ...
- phpmyadmin和网页上面的乱码问题
前段时间做了个留言板,但是总是出现乱码,而且出现了无法插入的情况:发现这么个问题:在phpmyadmin里面默认的编码是瑞士的一个编码:我就郁闷了为什么这么一个通用软件的编码放着UTF-8或者是GBK ...
- 应用安全 - 代码审计 - JavaScript
JavaScript Prototype污染
- jQ全选或取消全选
function checkAll(chkobj) { if ($(chkobj).children("span").text() == "全选" ...
- new Date() 对象及方法:
在别人的代码中见了两回 new Date().toLocaleString(),查了才知道,toLocaleString()是 根据本地时间格式,把 Date 对象转换为字符串.于是好奇new Dat ...
- Spring Boot系列(四) Spring Cloud 之 Config Client
Config 是通过 PropertySource 提供. 这节的内容主要是探讨配置, 特别是 PropertySource 的加载机制. Spring Cloud 技术体系 分布式配置 服务注册/发 ...
- 20190906 On Java8 第十八章 字符串
第十八章 字符串 +的重载与StringBuilder 用于String的+与+=是Java中仅有的两个重载过的操作符,Java不允许程序员重载任何其他的操作符.编译器自动引入了java.lang.S ...
- Java 操作pdf与excel
java 操作pdf组件 itextpdf <dependency> <groupId>com.itextpdf</groupId> <artifactId ...
- org.springframework.beans.BeanUtils的用法
s,t为对象BeanUtils.copyProperties(s, t); 将给定源bean的属性值复制到目标bean中 public static void copyProperties(Obje ...
- [Codeforces 1199C]MP3(离散化+二分答案)
[Codeforces 1199C]MP3(离散化+二分答案) 题面 给出一个长度为n的序列\(a_i\)和常数I,定义一次操作[l,r]可以把序列中<l的数全部变成l,>r的数全部变成r ...