Baidu 2017 spring recruit written exam real problem [programming question] look for triangle __ Internet machine Test

Source: Internet
Author: User

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&AMP;&AMP;P[J].C==P[K].C&AMP;&AMP;P[I].C==P[K].C) | | (P[I].C!=P[J].C&AMP;&AMP;P[J].C!=P[K].C&AMP;&AMP;P[I].C!=P[K].C))
                &&t>maxa) maxa=t;
    printf ("%.5f\n", Maxa);
return 0;
 }


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.