记录编号 328209 评测结果 AAAAAAAAAAA
题目名称 三角形牧场 最终得分 100
用户昵称 Gravatarrewine 是否通过 通过
代码语言 C++ 运行时间 1.138 s
提交时间 2016-10-23 20:18:03 内存使用 0.31 MiB
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <queue>
#include <cmath>
#include <algorithm>

using namespace std;

#define Rep(_i,z,zz) for(int _i=z;_i<=zz;_i++)
#define Min(a,b) ((a)<(b))?(a):(b);
#define Max(a,b) ((a)>(b))?(a):(b);

inline int read() {
	int tmp;bool flag = 0;char c;
	while((c=getchar())>'9'||c<'0')
	  if(c == '-') flag = 1;
	tmp = c-'0';
	while((c=getchar())<='9'&&c>='0')
	 tmp = ((tmp<<1)+(tmp<<3))+c-'0';
	return flag ? -tmp:tmp;  
}

int n,a[42],ans = -1,p[5];

void init() {
	Rep(i,1,n) {
		int tmp = rand()%n+1;
		int c = a[tmp];
		a[tmp] = a[i];
		a[i] = c; 
	}
}

int js(double a,double b,double c) {
//cout<<a<<" "<<b<<" "<<c<<endl;
	if(a>b+c || b>a+b || c>a+b)
      return -1;
    double p = double(a+b+c)/2.0;
    return int(100*sqrt(p*(p-a)*(p-b)*(p-c)));
}

void work() {
	init();
	p[1] = a[1];
	p[2] = a[2];
	p[3] = a[3];
	for (int i = 4;i <= n; i++) {
		int tt = 0,minn = 999999999;
		Rep(j,1,3) {
			if(minn > p[j]) {
				minn = p[j];
				tt = j;
			}
		}
		p[tt] += a[i];
	}
//cout<<p[1]<<" "<<p[2]<<" "<<p[3]<<endl;
	ans = max(ans,js(p[1],p[2],p[3]));
//cout<<ans<<endl;
}

int main () {
	freopen("pasture.in","r",stdin);
	freopen("pasture.out","w",stdout); 
    n = read();
    Rep(i,1,n) a[i] = read();
    Rep(i,1,100000) work();
    printf("%d",ans);
	return 0;
}