HDU 4617
复习了一下大一的东西 都忘记了
题意是 n 个无限长的圆柱
给你 n 然后 圆心 圆上2点 n个
求 能不能相交 相交 lucky
否则 输出最短距离
先求 2 平面 法向量 求出 这2个法向量 的法向量 n 然后取直线上2点 ab d = fabs(n*ab)/|n|;
难受
#include<stdio.h> #include<algorithm> #include<cstring> #include<string> #include<cmath> #include<vector> #include<queue> using namespace std; #define MAXN 510 #define inf 1000000000 struct point { double x,y,z; }z[MAXN][3],fa[MAXN]; double r[MAXN]; point de(point a,point b) { point c; c.x=a.x-b.x; c.y=a.y-b.y; c.z=a.z-b.z; return c; } point chaji(point a,point b) { point c; c.x=a.y*b.z-a.z*b.y; c.y=-(a.x*b.z-a.z*b.x); c.z=a.x*b.y-a.y*b.x; return c; } 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)); } double dianji(point a,point b) { return a.x*b.x+a.y*b.y+a.z*b.z; } double len(point a) { return sqrt(a.x*a.x+a.y*a.y+a.z*a.z); } int main() { int t; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); for(int i=1;i<=n;i++) { for(int j=0;j<3;j++) scanf("%lf%lf%lf",&z[i][j].x,&z[i][j].y,&z[i][j].z); } for(int i=1;i<=n;i++) { point a,b; a=de(z[i][1],z[i][0]); b=de(z[i][2],z[i][0]); point c; fa[i]=chaji(a,b); r[i]=dis(z[i][1],z[i][0]); } double ans =inf; int ok=0; for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { if(i==j) continue; point a =chaji(fa[i],fa[j]); point b =de(z[i][0],z[j][0]); double d = fabs(dianji(a,b))/len(a); if(d<=r[i]+r[j]) { ok=1; } ans = min(ans,d-r[i]-r[j]); } } if(ok==1) printf("Lucky\n"); else printf("%.2lf\n",ans); } return 0; }
posted on 2017-03-15 21:16 HelloWorld!--By-MJY 阅读(134) 评论(0) 编辑 收藏 举报