您的位置:首页 > 理论基础 > 计算机网络

【2015ZUFE新生赛网络同步赛C】【水题 贪心】boom x乘(y+z)尽可能大

2015-12-07 12:15 477 查看
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre(){freopen("c://test//input.in","r",stdin);freopen("c://test//output.out","w",stdout);}
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1,class T2>inline void gmax(T1 &a,T2 b){if(b>a)a=b;}
template <class T1,class T2>inline void gmin(T1 &a,T2 b){if(b<a)a=b;}
const int N=0,M=0,Z=1e9+7,ms63=1061109567;
int casenum,casei;
int n;
int a[1010];
int main()
{
while(~scanf("%d",&n))
{
for(int i=1;i<=n;++i)scanf("%d",&a[i]);
sort(a+1,a+n+1);
printf("%lld\n",LL(a
)*(a[n-1]+a[n-2]));
}
return 0;
}
/*
【trick&&吐槽】
乘法肯定要小心爆int啦!

【题意】
让你从n(3<=n<=1000)个数中选出3个数,x,y,z,使得x*(y+z)尽可能大。
并输出这个max(x*(y+z))

【类型】
贪心

【分析】
显然x,y,z是前三大的数,而且x最大。

*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  水题