HDU 4273 Rescue (three-dimensional convex package + center of gravity template) __hdu

Source: Internet
Author: User
Tags float number

Rescue Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 382 accepted Submission (s): 282


Problem Description I work at NASA outer Spaces Rescue team which needs a much courage and patient. In the daily life, I always receive a lot of the mission, and I must complete it right now.
Today, team leader announced me this there is a huge spaceship dropping to anchor in the out spaces, and we should reach there For rescue. As a working principle, at the (a), we should check whether there are persons living in the spaceship. So we carry a kind of machine called Life sensor which can sense the life phenomenon when the distance between the machine And the living is not farther than the sense radius.
I have read the designing paper of the spaceship in advance. It has a form of a convex polyhedron, and we can assume it is isodense. For best control, control center of the whole ship are located at the center of the Mass. It is sure this if someone is still alive and he would stay at the control center.
It's unfortunately that I find the door are stocked when I try to enter into the spaceship and so I can only sense the living Out of the. Now I have opened the machine and it ' s time to set the sense radius of it. I wonder the minimal radius of the machine which can allowe me to check whether there are persons living in the spaceship.

Input There are multiple test cases.
The contains an integer n indicating the number of vertices of the polyhedron. (4 <= n <= 100)
Each of the next n lines contains three integers xi, Yi, Zi, the coordinates of the polyhedron vertices ( -10,000 <= XI, Yi, zi <= 10,000).
It guaranteed that this given points are vertices of the convex polyhedron, and the polyhedron is non-degenerate.

Output for each test case, output a float number indicating the minimal radius of the machine. Your answer should accurate up to 0.001.

Sample Input

4 0 0 0 1 0 0 0 1 0 0 0 1 8 0 0 0 0 0 2 0 2-0-0 2 2 2 0 0 2 0 2 2 2 0-2
Sample Output
0.144 1.000
Source ACM/ICPC Asia Regional Changchun Online

Give you a convex polyhedron, to find the minimum distance of the center of gravity.

Search the template on the Internet, save it for use.

#include <stdio.h> #include <algorithm> #include <string.h> #include <math.h> #include <
Stdlib.h> using namespace std;
const int maxn=550;

const double eps=1e-8;
    struct point {double x,y,z; Point () {} point (double xx,double yy,double ZZ): X (xx), Y (yy), Z (ZZ) {}//two vector difference point operator-(const point P1
    ) {return point (X-P1.X,Y-P1.Y,Z-P1.Z);
    ///two vector and point operator + (const point p1) {return point (X+P1.X,Y+P1.Y,Z+P1.Z);
    }//fork by point operator * (const point P) {return point (y*p.z-z*p.y,z*p.x-x*p.z,x*p.y-y*p.x);
    Point operator * (double D) {return point (x*d,y*d,z*d);
    Point operator/(double D) {return point (X/D,Y/D,Z/D);
    //dot Multiply double operator ^ (point P) {return (X*P.X+Y*P.Y+Z*P.Z);

}
};
        struct Ch3d {struct face {//denotes convex package three dots on one side of the number int a,b,c;
    Indicates whether the surface belongs to the face bool OK on the final convex package;
    };
    Initial top pointsint n;
    Initial vertex point P[MAXN];
    The number of triangles on the surface of the convex package int num;
    Triangular face f[8*maxn on convex hull surface];
    triangular int g[maxn][maxn on convex hull surface];
    Vector length Double Vlen (point a) {return sqrt (A.X*A.X+A.Y*A.Y+A.Z*A.Z); }//fork by Point Cross (const point &a,const point &b,const point &c) {return point (B.Y-A.Y) * (c.z -A.Z)-(B.Z-A.Z) * (C.Y-A.Y), (B.Z-A.Z) * (c.x-a.x)-(b.x-a.x) * (C.Z-A.Z), (b.x-a.x) * (c
    . Y-a.y)-(B.Y-A.Y) * (c.x-a.x));
    }//Triangular area *2 double areas (point A,point b,point c) {return Vlen ((b-a) * (c-a));
    }//tetrahedron-direction Volume *6 double volume (point a,point b,point c,point D) {return (b-a) * (c-a) ^ (d-a);
        //Positive: points in the face with double dblcmp (point &p,face &f) {spot M=P[F.B]-P[F.A];
        Point N=P[F.C]-P[F.A];
        Point T=P-P[F.A];
    Return (m*n) ^t; } void Deal (int p,int a,int b) {int f=g[a][b];//search for another planar face ad adjacent to the edgeD
            if (F[f].ok) {if (dblcmp (p[p],f[f)) >eps) DFS (P,F);
                else {add.a=b;
                Add.b=a;
                add.c=p;//here to pay attention to order, to become the right hand system add.ok=true;
                G[p][b]=g[a][p]=g[b][a]=num;
            F[num++]=add;
        } void Dfs (int p,int now) {//recursive search for all face f[now].ok=0 that should be removed from the convex package;
        Deal (P,F[NOW].B,F[NOW].A);
        Deal (P,F[NOW].C,F[NOW].B);
    Deal (P,F[NOW].A,F[NOW].C);
        BOOL Same (int s,int t) {point &a=P[F[s].a];
        Point &b=P[F[s].b];
        Point &c=P[F[s].c];
               Return Fabs (Volume (a,b,c,p[f[t].a])) <eps && fabs (Volume (a,b,c,p[f[t].b)) <eps &&
    Fabs (Volume (A,B,C,P[F[T].C)) <eps;
        //build three-dimensional convex package void create () {int i,j,tmp;

        Face add;
        num=0;
        if (n<4) return;
    //**********************************************    This paragraph is to ensure that the first four points are not coplanar bool flag=true;
                For (I=1 i<n; i++) {if (Vlen (p[0]-p[i)) >eps) {swap (p[1],p[i));
                Flag=false;
            Break
        } if (flag) return;
        Flag=true; Make the first three dots not collinear for (i=2 i<n; i++) {if (Vlen ((p[0]-p[1)) * (p[1]-p[i)) >eps) {Swap (p[2
                ],p[i]);
                Flag=false;
            Break
        } if (flag) return;
        Flag=true;
                Make the first four points not coplanar for (int i=3; i<n; i++) {if (Fabs ((p[0]-p[1)) * (p[1]-p[2)) ^ (p[0]-p[i)) >eps) {
                Swap (p[3],p[i]);
                Flag=false;
            Break
        } if (flag) return;
            For (i=0 i<4; i++) {add.a= (i+1)%4;
            add.b= (i+2)%4;
            Add.c= (i+3)%4;
            Add.ok=true; if (DBLCMP (p[i],add) >0) swap (ADD.B,ADD.C);
            G[add.a][add.b]=g[add.b][add.c]=g[add.c][add.a]=num;
        F[num++]=add; For (i=4 i<n; i++) {for (j=0; j<num; J + +) {if f[j].ok&&dblcmp (p[i],f[
                    J]) {>eps) {DFS (I,J);
                Break
        }} Tmp=num;

    For (i=num=0 i<tmp; i++) if (F[i].ok) f[num++]=f[i];
        //surface area double () {double res=0;
            if (n==3) {point P=cross (p[0],p[1],p[2]);
            Res=vlen (p)/2.0;
        return res;
        for (int i=0; i<num; i++) Res+=area (P[F[I].A],P[F[I].B],P[F[I].C));
    return res/2.0;
        Double volume () {double res=0;
        Point tmp (0,0,0);
        for (int i=0; i<num; i++) Res+=volume (TMP,P[F[I].A],P[F[I].B],P[F[I].C));
    return Fabs (res/6.0); }//Surface triangle number int TriaNgle () {return num;
        ///Surface Polygon number int polygon () {int i,j,res,flag;
            for (i=res=0; i<num; i++) {flag=1;
                    For (j=0 j<i; j + +) if (same (i,j)) {flag=0;
                Break
        } Res+=flag;
    return res;
        }//three-dimensional convex center point barycenter () {point ans (0,0,0), O (0,0,0);
        Double all=0;
            for (int i=0; i<num; i++) {double vol=volume (o,p[f[i].a],p[f[i].b],p[f[i].c]);
            Ans=ans+ (o+p[f[i].a]+p[f[i].b]+p[f[i].c])/4.0*vol;
        All+=vol;
        } Ans=ans/all;
    return ans; //point to Surface distance double ptoface (points p,int i) {return fabs (Volume (p[f[i].a],p[f[i].b],p[f[i].c],p)/vlen (p[f[i
    ].B]-P[F[I].A]) * (P[F[I].C]-P[F[I].A));
}
};

Ch3d Hull; int main () {while (scanf ("%d", &AMP;HULL.N) ==1) {for (int i=0; i 


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.