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 ...
随机推荐
- PHP上传文件到阿里云OSS,nginx代理访问
1. 阿里云OSS创建存储空间Bucket(读写权限为:公共读) 2. 拿到相关配置 accessKeyId:********* accessKeySecret:********* endpoint: ...
- vue 常用插件,保存
UI组件 element- 饿了么出品的Vue2的web UI工具套件 Vux- 基于Vue和WeUI的组件库 mint-ui- Vue 2的移动UI元素 iview- 基于 Vuejs 的开源 UI ...
- data plugin for vs2019
Reporting Service projects for VS 2019https://marketplace.visualstudio.com/items?itemName=ProBITools ...
- java webservice - cxf使用总结 一
1.创建maven项目 加入pom依赖 <dependency> <groupId>org.apache.cxf</groupId> <artifactId& ...
- [luogu4768] [NOI2018] 归程 (Dijkstra+Kruskal重构树)
[luogu4768] [NOI2018] 归程 (Dijkstra+Kruskal重构树) 题面 题面较长,这里就不贴了 分析 看到不能经过有积水的边,即不能经过边权小于一定值的边,我们想到了kru ...
- host文件无操作权限
把先用其它启动方式启动电脑,如winpe(网上有制作方法,很简单的),启动后找到FWPKCLNT.SYS所在文件夹, 一般在c/windows/system32/drivers,将drivers文件夹 ...
- NGUI的怎么在一个Gameobject(游戏物体)中调用另一个Gameobject(游戏物体)的脚本(C#)
一,在C#代码中,我们都知道可以给游戏物体添加一个脚本,如下图 二,在当前我们是可以调用到该游戏物体脚本定义的变量,但是我们要在其他脚本调用怎么办?如下代码, KnapSackItem kn = it ...
- 23、前端知识点--webpack的使用详解
Webpack 是当下最热门的前端资源模块化管理和打包工具. https://www.cnblogs.com/zhangruiqi/p/7656206.html
- k3 cloud出现应收单下推收款单,把收款单是结算方式修改成银行承兑汇票之后保存提示:收款单明细中结算方式为票据业务的实收金额之和不等于票据的当前占用金额之和,请检查数据!
收款单结算方式选择[银行承兑汇票],系统就默认该笔业务在系统中要存在一张应收票据.则在应收票据页签,需要选择一张出纳的应收票据(要先存在应收票据,才能保存单据,相当于是根据这张票据审核生成的这张收单单 ...
- sqoop简单使用
一,通过sqoop将MySQL里面的数据加载到HDFS 先查看有哪些数据库 查看表person sqoop list-databases --connect jdbc:mysql://ly-p2p4: ...