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 ...
随机推荐
- Caffe:深入分析(怎么训练)
main() 首先入口函数caffe.cpp int main(int argc, char** argv) { ...... ) { #ifdef WITH_PYTHON_LAYER try { # ...
- 16/7/7_PHP-访问控制
访问控制 前面的小节,我们已经接触过访问控制了,访问控制通过关键字public,protected和private来实现.被定义为公有的类成员可以在任何地方被访问.被定义为受保护的类成员则可以被其自身 ...
- GIt 工作区与暂存区
转载:https://www.liaoxuefeng.com/wiki/896043488029600/897271968352576 工作区与暂存区 工作区(Working Directory) 就 ...
- python接口自动化:响应内容中json字符串对象的处理
实现代码如下: import json #定义一个字典.一个列表.两个字符串({}中必须是双引号) di1={"} di2=[{"}] di3='{"name" ...
- Java学习day6数组
---恢复内容开始--- Java数组 Java 语言中提供的数组是用来存储固定大小的同类型元素.你可以声明一个数组变量,如 numbers[100] 来代替直接声明 100 个独立变量 number ...
- Oracle数据库SQL语句的分类
1986年10月,美国国家标准协会对SQL进行规范后,以此作为关系式数据库管理系统的标准语言,1987年在国际标准组织的支持下成为国际标准.不过各种通行的数据库系统其实在实践过程中都对SQL规范的作了 ...
- $.ajax()方法详解(网上引用)
jquery中的ajax方法参数总是记不住,这里记录一下. 1.url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. 2.type: 要求为String类型的参数,请求方式(p ...
- Codeforces - 1199D - Welfare State - 单调栈 / 线段树
https://codeforc.es/contest/1199/problem/D 其实后来想了一下貌似是个线段树的傻逼题. 单调栈是这样思考的,每次单点修改打上一个最终修改的时间戳.每次全体修改就 ...
- sys模块与shutil模块
#coding=utf-8 import sys ## sys.argv #从命令行获取参数 import shutil #文件.文件夹.压缩包.处理模块 f1 = open("test.t ...
- HashMap对象转换为JavaBean对象
问题: 在日常代码中,使用 spring包中的 BeanUtils.copyProperties(source,target),可以将A对象的属性复制到B对象中,但是有个问题 无法将HashMap中的 ...