Time limit: 1 seconds
Space limit: 32768K three-dimensional space with n points, each point may be one of three colors, three colors are red, green and blue, respectively, ' R ', ' G ', ' B '.
Now it's time to figure out three points and make a triangle that's the largest area of the triangle.
But the triangle must be satisfied: The three-point color is either all the same or all different.
Enter a description:
First, enter the number of points in a positive integer n three-dimensional coordinate system. (N <=)
Next n rows, each row is entered with a C x y z,c as one of the ' R ', ' G ', ' B '. The x,y,z is the coordinates of the point. (coordinates are integers from 0 to 999)
Output Description:
Output a number that represents the largest triangular area and retains 5 decimal places.
Enter Example 1:
5
r 0 0 0
R 0 4 0
R 0 0 3
G EUR 7
G 12 16 + 8
Output Example 1:
6.00000
#include <cstdio> #include <cmath> const int maxn=51;
struct point{char c;
int x,y,z;
}P[MAXN];
Double Dis (point A,point b) {return sqrt (a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (A.Y-B.Y) + (a.z-b.z) * (A.Z-B.Z));
BOOL Is_san (Point A,point b,point c) {double X=dis (a,b);
Double Y=dis (B,C);
Double Z=dis (A,C);
if (x+y>z&&x+z>y&&y+z>x) return true;
else return false;
Double area (Point A,point b,point c) {double X=dis (a,b);
Double Y=dis (B,C);
Double Z=dis (A,C);
Double p= (x+y+z)/2;
return sqrt (p* (p-x) * (p-y) * (p-z));
int main () {int n;
while (scanf ("%d", &n) ==1) {for (int i=0;i<n;i++) {getchar ();
scanf ("%c%d%d%d", &p[i].c,&p[i].x,&p[i].y,&p[i].z);
Double maxa=-1,t;
for (int i=0;i<n-2;i++) for (int j=i+1;j<n-1;j++) for (int k=j+1;k<n;k++) { if (Is_san (P[i],p[j],p[k])) T=areA (p[i],p[j],p[k]); if ((P[I].C==P[J].C&&P[J].C==P[K].C&&P[I].C==P[K].C) | | (P[I].C!=P[J].C&&P[J].C!=P[K].C&&P[I].C!=P[K].C))
&&t>maxa) maxa=t;
printf ("%.5f\n", Maxa);
return 0;
}