HDU 4273 Rescue 제3 7 회 ACM / ICPC 장춘 지구 사 이 버 전 1007 문제 (3 차원 볼록 팩 + 중심 + 점 면 거리)
25644 단어 ICPC
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 97 Accepted Submission(s): 65
Problem Description
I work at NASA outer space rescue team which needs much courage and patient. In daily life, I always receive a lot of mission, and I must complete it right now.
Today, team leader announced me that there is a huge spaceship dropping anchor in the out space, and we should reach there for rescue. As a working principle, at first, 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 is located at the center of the mass. It is sure that if someone is still alive, he will stay at the control center.
It's unfortunately that I find the door is stocked when I try to enter into the spaceship, so I can only sense the living out of the space ship. 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 first line 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 the 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 2 2
Sample Output
0.144 1.000
Source
2012 ACM/ICPC Asia Regional Changchun Online
Recommend
liuyiding
템 플 릿 문제...
기 하 를 계산 할 때 는 그래도 많이 만들어 야 하고, 양식 을 많이 준비 해 야 한다!!!
/*
HDU 4273 Rescue
,
: + +
*/
#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){}
//
Point operator -(const Point p1)
{
return Point(x-p1.x,y-p1.y,z-p1.z);
}
//
Point operator +(const Point p1)
{
return Point(x+p1.x,y+p1.y,z+p1.z);
}
//
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);
}
//
double operator ^(Point p)
{
return (x*p.x+y*p.y+z*p.z);
}
};
struct CH3D
{
struct face
{
//
int a,b,c;
//
bool ok;
};
//
int n;
//
Point P[MAXN];
//
int num;
//
face F[8*MAXN];
//
int g[MAXN][MAXN];
//
double vlen(Point a)
{
return sqrt(a.x*a.x+a.y*a.y+a.z*a.z);
}
//
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)
);
}
// *2
double area(Point a,Point b,Point c)
{
return vlen((b-a)*(c-a));
}
// *6
double volume(Point a,Point b,Point c,Point d)
{
return (b-a)*(c-a)^(d-a);
}
// :
double dblcmp(Point &p,face &f)
{
Point 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];//
face add;
if(F[f].ok)
{
if(dblcmp(P[p],F[f])>eps)
dfs(p,f);
else
{
add.a=b;
add.b=a;
add.c=p;// ,
add.ok=true;
g[p][b]=g[a][p]=g[b][a]=num;
F[num++]=add;
}
}
}
void dfs(int p,int now)//
{
F[now].ok=0;
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;
}
//
void create()
{
int i,j,tmp;
face add;
num=0;
if(n<4)return;
//**********************************************
//
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;
//
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;
//
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];
}
//
double area()
{
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);
}
//
int triangle()
{
return num;
}
//
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;
}
//
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;
}
//
double ptoface(Point 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()
{
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
while(scanf("%d",&hull.n)==1)
{
for(int i=0;i<hull.n;i++)
{
scanf("%lf%lf%lf",&hull.P[i].x,&hull.P[i].y,&hull.P[i].z);
}
hull.create();
Point p=hull.barycenter();
double minn=1e20;
for(int i=0;i<hull.num;i++)
{
minn=min(minn,hull.ptoface(p,i));
}
printf("%.3lf
",minn);
}
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
2013 ACMICPC 항주 라이브 I 문제사고방식: 기억화 검색. dp[S]는 남은 상태가 S일 때 기수가 마법석을 최대 얼마나 얻을 수 있는지 나타낸다....
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.