Largest Point

原题地址
这道题意思就是atiti+btj最大,i≠j.这道题最坑的是时间给的少 ,容易超时。所以无法用sort。于是需要我们自己保存最大的数和最小的数,第二大的数和第二小的数。由于这里我对最大的数和最小的数,第二大的数和第二小的数想的比较简单,所以做的麻烦的同时还不对 。这里可以整理出最大的和最小的,第二大的和第二小的a ti * ti和btj,用结构体分别存,因为条件说i≠j,在判断一下atiti和btj的T是不是一个t,就行。
附上代码:

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <iomanip>
#include <string>
#include <sstream>
#include  <list>
//#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
/*
int cmp(shi a,shi b)
{
    return a.x<b.x;
}
long long cmd(long long a, long long  b)
{
    return a > b;
}*/

struct shi{
    long long one = -INF;
    long long  two = -INF;
    long long place;
};
int main()
{
    long long t;
    scanf("%lld",&t);
    for(long long i=1;i<=t;i++)
    {
        long long n, a , b,result=0;
        struct shi ans[2],res[2];
         //getchar();
        scanf("%lld %lld %lld",&n,&a,&b);
        for(long long j=1;j<=n;j++){
            long long o=0;
            scanf("%lld",&o);
            long long m1,m2;
            m1 = a*o*o;
            m2 = b*o;
            if(m1>=ans[0].one){
                ans[1].one = ans[0].one;
                ans[1].place = ans[0].place;
                ans[0].one = m1;
                ans[0].place = j;
            }
            else
                if(m1>ans[1].one){
                ans[1].one = m1;
                ans[1].place = j;
            }
            if(m2>=res[0].two){
                res[1].two = res[0].two;
                res[1].place = res[0].place;
                res[0].two = m2;
                res[0].place = j;
            }
            else
                if(m2>res[1].two){
                res[1].two = m2;
                ans[1].place = j;
            }
        }
        if(res[0].place==ans[0].place){
            result = max(ans[0].one+res[1].two,ans[1].one+res[0].two);
        }
        else {
            result = ans[0].one+res[0].two;
        }
        printf("Case #%d:",i);
        printf("%lld\n",result);
    }

    return 0;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值