Little Zu Chongzhi's Triangles
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others)
Total Submission(s): 2515 Accepted Submission(s): 1427
It is said in some legend story books that when Zu was a little boy, he liked mathematical games. One day, his father gave him some wood sticks as toys. Zu Chongzhi found a interesting problem using them. He wanted to make some triangles by those sticks, and he wanted the total area of all triangles he made to be as large as possible. The rules were :
1) A triangle could only consist of 3 sticks.
2) A triangle's vertexes must be end points of sticks. A triangle's vertex couldn't be in the middle of a stick.
3) Zu didn't have to use all sticks.
Unfortunately, Zu didn't solve that problem because it was an algorithm problem rather than a mathematical problem. You can't solve that problem without a computer if there are too many sticks. So please bring your computer and go back to Zu's time to help him so that maybe you can change the history.
The first line is an integer N(3 <= N<= 12), indicating the number of sticks Zu Chongzhi had got. The second line contains N integers, meaning the length of N sticks. The length of a stick is no more than 100. The input ends with N = 0.
1 1 20
7
3 4 5 3 4 5 90
0
13.64
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<stack>
#include<map>
#include<vector>
#include<queue>
using namespace std;
const int MAXN=1e5+;
const double eps=1e-;
const int mod=1e9+;
#define INF 0x7fffffff
#define ll long long
#define edl putchar('\n')
#define useit ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define mst(a) memset(a,0,sizeof(a))
#define mstn(a,n) memset(a,n,sizeof(a))
//struct num{int a,i;}a[MAX];
//bool cmp(const num &a,const num &b){return a.a>b.a;}
//double cross(point a,point b){return (a.x*b.y-a.y*b.x);}
//double dot(point a,point b){return (a.x*b.x+a.y*b.y);}
float ans,a[];
int b[],n;
float solve(float a,float b,float c)
{
float p=(a+b+c)/;
if(b>c)
swap(b,c);
if(a>b)
swap(a,b);
if(b>c)
swap(b,c);
if((b+a)<=c)
return 0.00;
else
return sqrt(p*(p-a)*(p-b)*(p-c));
} void dfs(int time,float are)
{
if(time==)
ans=max(ans,are);
else
{
FOR(i,,n)
{
if(b[i])continue;
else
FOR(j,i+,n)
{
if(j==i||b[j])continue;
else
FOR(k,j+,n)
{
if(k==i||k==j||b[k])continue;
else
{
b[i]=,b[j]=,b[k]=;
dfs(time-,are+solve(a[i],a[j],a[k]));
b[i]=,b[j]=,b[k]=;
}
}
}
}
}
} int main()
{
while(scanf("%d",&n)&&n)
{
ans=0.00;
FOR(i,,n)
scanf("%f",&a[i]),b[i]=;
dfs(n/,);
printf("%.2f\n",ans);
}
}