刷题与ZZ错误记录15

LightOJ-1240 Point Segment Distance (3D)

AC代码

#include<cstdio>
#include<cmath>
using namespace std;
int x1,yy1,z1,x2,y2,z2,x,y,z,T,t,tt;
double bili,l,r,mid1,mid2;
inline double cal(double m){
    double xx=x1+(x2-x1)*m;
    double yy=yy1+(y2-yy1)*m;
    double zz=z1+(z2-z1)*m;
    return sqrt((x-xx)*(x-xx)+(y-yy)*(y-yy)+(z-zz)*(z-zz));
}
int main(){
    scanf("%d",&T);
    while(++t<=T){
        scanf("%d%d%d%d%d%d%d%d%d",&x1,&yy1,&z1,&x2,&y2,&z2,&x,&y,&z);
        l=0;r=1;tt=0;
        while(tt<=100){
            mid1=(r+l+l)/3;
            mid2=(r+l+r)/3;
            //cout<<l<<"\t"<<mid1<<"\t"<<mid2<<"\t"<<r<<endl;
            if(cal(mid1)<cal(mid2)){
                r=mid2;
            }else{
                l=mid1;
            }
            tt++;
        }
        printf("Case %d: %.6lf\n",t,cal(r));
    }
}
//----------------
//----------

页面: 1 2 3 4 5 6

点赞

发表评论

电子邮件地址不会被公开。必填项已用 * 标注