Largest Point hdu 5461

http://acm.hdu.edu.cn/showproblem.php?pid=5461

分析:一开始很撒很撒的分了很多种情况去写了,后来发现可以先储存a*num*num和b*num的值,然后再判断最大值。。

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <math.h>

using namespace std;

#define met(a, b) memset(a, b, sizeof(a))
const int maxn=5000007;
#define oo 0x3f3f3f3f
const int MOD = 1e9+7;

typedef long long LL;
int num[maxn];

struct node
{
    LL sum;
    int index;
}a[maxn], b[maxn];

int cmp(node p, node q)
{
    return p.sum>q.sum;
}

int main()
{
    int T, n, A, B, cnt=1;
    LL  num;

    scanf("%d", &T);

    while(T --)
    {
        scanf("%d %d %d", &n, &A, &B);

        for(int i=0; i<n; i++)
        {
            scanf("%lld", &num);
            a[i].sum=A*num*num;
            a[i].index = i;
            b[i].sum=B*num;
            b[i].index = i;
        }

        sort(a, a+n, cmp);
        sort(b, b+n, cmp);

        if(a[0].index != b[0].index)
            printf("Case #%d: %lld\n", cnt++, a[0].sum+b[0].sum);
        else
        {
            LL p = max(a[0].sum+b[1].sum, a[1].sum+b[0].sum);
            printf("Case #%d: %lld\n",cnt++, p);
        }
    }
    return 0;
}

时间: 2024-10-08 15:47:40

Largest Point hdu 5461的相关文章

hdu 5461 Largest Point 暴力

Largest Point Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5461 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

hdu 5461 Largest Point

Thinking about it: 对于式子 a * ti * ti + b * tj,可以看作时有两部分构成 a * ti * ti 和 b * tj,如果整个式子要最大,则要求这两部分都要尽量大.那么再读入数据 t 时,那么就可以构造两个数组,一个存储a * ti * ti ,另一个存储 b * tj.在选取时就产生了两种方案: 1. 先选取 a * ti * ti 最大的,接着再 i != j 的基础上, 选择 b * tj 最大的. 2. 先选取 b * tj 最大的,接着再 i !=

hdu 5461(分类讨论)

Largest Point Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 1485    Accepted Submission(s): 588 Problem Description Given the sequence A with n integers t1,t2,?,tn. Given the integral coeffici

HDU 1506 Largest Rectangle in a Histogram (dp左右处理边界的矩形问题)

E - Largest Rectangle in a Histogram Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1506 Appoint description: Description A histogram is a polygon composed of a sequence of rectangles aligned a

HDU 1506 Largest Rectangle in a Histogram

Largest Rectangle in a Histogram Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 150664-bit integer IO format: %I64d      Java class name: Main A histogram is a polygon composed of a sequence of rectangles al

hdu 2870 Largest Submatrix

Largest Submatrix http://acm.hdu.edu.cn/showproblem.php?pid=2870 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description Now here is a matrix with letter 'a','b','c','w','x','y','z' and you can change '

HDU 2870 Largest Submatrix (单调栈)

http://acm.hdu.edu.cn/showproblem.php?pid=2870 Largest Submatrix Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1569    Accepted Submission(s): 748 Problem Description Now here is a matrix wit

HDU 1505 Largest Rectangle in a Histogram &amp;&amp; HDU 1506 City Game(动态规划)

1506题意:给你连续的直方图(底边边长为1),求连续的矩阵面积. 对每个直方图,分别向左向右进行扩展. #include<cstdio> #include<stdlib.h> #include<string.h> #include<string> #include<map> #include<cmath> #include<iostream> #include <queue> #include <sta

(hdu step 2.1.3)Largest prime factor(求一个数的最大质因子的位置)

题目: Largest prime factor Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4868 Accepted Submission(s): 1452   Problem Description Everybody knows any number can be combined by the prime number.Now,