Bnu4078距离判定

来源:互联网 发布:apache服务启动失败 编辑:程序博客网 时间:2024/05/16 15:45

距离判定
Time Limit: 1000msMemory Limit: 65536KB 64-bit integer IO format: %lld Java class name: Main
Prev Submit Status Statistics Discuss Next
Type:
None

Tag it!
2008年杭州赛区的比赛在杭州电子科技大学举行。 北师大一行一共7人(两队+1教练)参与了这次比赛。比赛前一天,uTOPia和Archimedes的队员分开在杭电校园中闲逛,DXY作为教练,想知道他离哪一队更近。 他与某一队之间的距离定义为他离连接该队两队员的直线的距离。

Input
对于每一组数据: 第一、二行:每行两个数,表示uTOPia队队员所在位置坐标。 第三、四行:每行两个数,表示Archimedes队队员所在位置坐标。 第五行:每行两个数,表示DXY所在位置坐标。 以EOF作为结束。

Output
对于每一组数据: 第一行:离得更近的那支队伍的名称,若距离一样,输出“Equal”。
Sample Input
-1.5 0
-1.5 1.5
1.5 -1.5
1.5 0
0 0
-1.6 0
-1.6 1.5
1.5 -1.5
1.5 0
0 0
-1.5 0
-1.5 1.5
1.6 -1.5
1.6 0
0 0
Sample Output
Equal
Archimedes
uTOPia

模板

#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>using namespace std;/*double PointToSegDist(double x, double y, double x1, double y1, double x2, double y2){    double cross = (x2 - x1) * (x - x1) + (y2 - y1) * (y - y1);    if (cross <= 0) return sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1));    double d2 = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);    if (cross >= d2) return sqrt((x - x2) * (x - x2) + (y - y2) * (y - y2));    double r = cross / d2;    double px = x1 + (x2 - x1) * r;    double py = y1 + (y2 - y1) * r;    return sqrt((x - px) * (x - px) + (py - y1) * (py - y1));}*/double PointToSegDist(double a1,double b1,double a2,double b2,double a,double b){    if(a2!=a1)    {        double k=(b2-b1)/(a2-a1);        return fabs((b-b1)-k*(a-a1))/sqrt(1+k*k);    }    else        return fabs(a-a1);}int main(){    double x1,y1,x2,y2,x3,y3,x4,y4;    double stx,sty;    while(scanf("%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4,&stx,&sty)!=EOF)    {        double s1=PointToSegDist(x1,y1,x2,y2,stx,sty);        double s2=PointToSegDist(x3,y3,x4,y4,stx,sty);        if(s1<s2)        printf("uTOPia\n");        else if(s1==s2)        printf("Equal\n");        else        printf("Archimedes\n");    }    return 0;}
0 0
原创粉丝点击