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;
}