hdu5461 Largest Point(沈阳网赛)

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

Source

2015 ACM/ICPC Asia Regional Shenyang Online

题意:求a*t1*t1+b*t2的值最大。

分析:数据不大,可以直接暴力求解,详解见代码。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
const double eps = 1e-6;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;
#define ll long long
#define CL(a) memset(a,0,sizeof(a))

ll T,n,a,b;
ll t[1000010];
ll min1,min2,max1,max2,k;//分别存最小的数、第二小的数、最大的数、第二大的数和最接近0的数

int main ()
{
    scanf ("%lld",&T);
    for (int cas=1; cas<=T; cas++)
    {
        scanf ("%lld%lld%lld",&n,&a,&b);
        k=INF;
        for (int i=0; i<n; i++)
        {
            scanf ("%lld",&t[i]);
        }
        cout<<"Case #"<<cas<<": ";
        sort(t, t+n);
        for (int i=0; i<n; i++)
        {
            if (t[i]<=0&&t[i+1]>=0)
                k=min(-t[i], t[i+1]);
        }
        min1=t[0]; min2=t[1];
        max1=t[n-1]; max2=t[n-2];//找出这五个数
        if (a<0&&b<0)//然后就是苦逼的找最大解了,注意负数的平方为正数
        {
            printf ("%lld\n",a*k*k+b*min1);
        }
        else if (a<0&&b>0)
        {
            printf ("%lld\n",a*k*k+b*max1);
        }
        else if (a>0&&b<0)
        {
            printf ("%lld\n",max(max(a*max1*max1+b*min1, a*min1*min1+b*min2), a*min2*min2+b*min1));
        }
        else if (a>0&&b>0)
        {
            printf ("%lld\n",max(max(a*max1*max1+b*max2, a*max2*max2+b*max1), a*min1*min1+b*max1));
        }
        else printf ("0\n");
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-08-10 23:19:54

hdu5461 Largest Point(沈阳网赛)的相关文章

【转】HDU 6194 string string string (2017沈阳网赛-后缀数组)

转自:http://blog.csdn.net/aozil_yang/article/details/77929216 题意: 告诉你一个字符串和k , 求这个字符串中有多少不同的子串恰好出现了k 次. 思路: 后缀数组. 我们先考虑至少出现k 次的子串, 所以我们枚举排好序的后缀i (sa[i]) . k段k 段的枚举. 假设当前枚举的是 sa[i]~sa[i + k -1] 那么假设这一段的最长公共前缀  是L 的话. 那么就有L 个不同的子串至少出现了k次. 我们要减去至少出现k + 1次

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: 88 Case #4: 352 Case #5: 318505405 Case #6: 391786781 Case #7: 133875314 Case #8: 83347132 Case #9: 16520782 题目要求当前字符串序列中某项里cff前缀两两间差值的和. 假设已经纪录了cff前缀的

2015年沈阳网赛 Jesus Is Here(DP中的计数问题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5459 题目描述:给定一个递推得来的字符串,问字符串中不同cff之间的距离之和, 递推规则: s1=c; s2=ff sn=s[n-2]s[n-1]; 可以观察到任意一个c都被两个ff包含,所以相当于求任意两个c之间的距离之和. 设s[n-2]为p1,p2,p3,,,,p[x],s[n-1]为q1,q2,q3,,,,q[y]; X和y分别为字符串中c的个数:设cnt_c[i]为第i个字符串中c的个数,

hdu 5455 (2015沈阳网赛 简单题) Fang Fang

题目;http://acm.hdu.edu.cn/showproblem.php?pid=5455 题意就是找出所给字符串有多少个满足题目所给条件的子串,重复的也算,坑点是如果有c,f以外的字符也是不满足条件的,还有我被坑了的地方就是当输入很多f的时候,我尽然脑抽的 认为这是不满足条件的,注意这两点就行了,直接暴力 1 #include<cstdio> 2 #include<cstring> 3 using namespace std; 4 int main() 5 { 6 int

hdu5459 Jesus Is Here(沈阳网赛)

Jesus Is Here Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 65535/102400 K (Java/Others) Total Submission(s): 257 Accepted Submission(s): 175 Problem Description I've sent Fang Fang around 201314 text messages in almost 5 years. Why can't she

hdu 5459 Jesus Is Here 沈阳网赛

按照这个规律找出来的不断取模之下会得负数.需要(ans+mod)%mod,化为正数. #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define ll __int64 const ll mod=530600414; const int maxn=201399; ll w[maxn],ans[maxn],num[maxn],len[maxn]; void init(

hdu 5459(2015沈阳网赛) Jesus Is Here

题目;http://acm.hdu.edu.cn/showproblem.php?pid=5459 题意 给出一组字符串,每个字符串都是前两个字符串相加而成,求第n个字符串的c的各个坐标的差的和,结果要模530600414. 很容易看出字符串的长度及c的个数都是由斐波那契数列构成的,得到最后结果是ans[i]=ans[i-1]+ans[i-2]+x,要求的就是x 假设第n项中字符'c'的个数为cn,字符'c'坐标之和为sn,字符串长度为ln 当形成第i个字符串的时候对于第i-1个字符串来说,这个

2015长春、沈阳网络赛总结

我所说的总结并不是谈什么题目解法之类的东西 这些东西网上有很多题解 说说这两场网赛吧! 这两场我的状态还行,只是xiaodong还没有找到状态,长春赛lucas+中国剩余定理他硬是打了一整场,还是没打出来,版题没打出来确实不该 wzb状态一般,不过看题的能力依然那么厉害 长春赛中,很遗憾的只出了5道题,按当时过题数目,应该是7道德,可是小东的lucas那题没打出来,而我打得后缀数组那题,当顺时针的时候不用看是否是下标最前面的,但是反过来就需要看了,当时想当然的认为不用,交了4发,一直wa到比赛结

ACM学习历程—HDU 5023 A Corrupt Mayor&#39;s Performance Art(广州赛区网赛)(线段树)

Problem Description Corrupt governors always find ways to get dirty money. Paint something, then sell the worthless painting at a high price to someone who wants to bribe him/her on an auction, this seemed a safe way for mayor X to make money. Becaus