Try to select 3 sticks with a large number of sides to form a triangle until you can select it.
It's easier to calculate the triangle area here or use Helen's formula.
1#include <iostream>2#include <algorithm>3#include <cmath>4#include <cstring>5#include <iomanip>6 using namespacestd;7 8 DoubleAbs (Doublex)9 {Ten returnx>=0? X:-x; One } A - Doublea[ the]; - BOOLvis[ the]; the - intMain () - { -Cin.sync_with_stdio (false); + intN; - Doublex, y, z, ans; + while(Cin >> N &&N) A { at for(inti =0; I<n; i++ ) - { -CIN >>A[i]; - } -memset (Vis,false,sizeof(Vis)); -Sort (A, A +n); inAns =0; - for(inti = n1; i>=2; i-- ) to { + if( !Vis[i]) - { thex =A[i]; *y = z =-1; $ intj = I1;Panax Notoginseng while(j>=0 ) - { the if( !Vis[j]) + { Ay =A[j]; the Break; + } ---J; $ } $ intK = J1; - while(k>=0 ) - { the if( !Vis[k]) - {Wuyiz =A[k]; the Break; - } Wu--K; - } About if(y!=-1&& z!=-1&& y+z>x) $ { - DoubleMid = (x + y + z)/2; -Ans + = sqrt (Mid * ABS (MID-X) * ABS (MID-Y) * ABS (mid-z)); -Vis[i] = vis[j] = Vis[k] =true; A } + } the } -cout << Setiosflags (iOS::fixed); $cout << Setprecision (2) << ans <<Endl; the } the return 0; the}View Code
hdu--5135--Greedy