题解:
贪心从大到小排序加遍历,三个一起遍历从大到小,如果满足三角形条件都可以加上答案。
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <stack>
#include <cmath>
#include <deque>
#include <queue>
#include <list>
#include <set>
#include <map>
#define mem(a, b) memset(a, b, sizeof(a))
#define pi acos(-1)
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn = 15;
double line[maxn];
int main(){
int n;
while(scanf("%d", &n), n){
for(int i = 0l; i < n; i++){
scanf("%lf", &line[i]);
}
sort(line, line+n);
double ans = 0;
for(int i = n-3; i >= 0;){
if(line[i]+line[i+1] > line[i+2]){
double p = (line[i]+line[i+1]+line[i+2])/2.0;
ans += sqrt(p*(p-line[i+1])*(p-line[i])*(p-line[i+2]));
i -= 3;
}
else{
i--;
}
}
printf("%.2lf\n", ans);
}
}