• UVa 10697


    题目:已知三点。求到三点距离同样的点。

    分析:计算几何。分三类情况讨论:

                1.三点共线,不成立。

                2.多点重叠,有多组解。

                3.是三角形,输出中点。

    说明:注意绝对值小于0.05的按0计算;负数的四舍五入与正数不同,-0.05的%.1lf输出是 -0.0。

    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    double dist( double x0, double y0, double x1, double y1 )
    {
    	return sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0));
    }
    
    double deal( double x )
    {
    	double esp = 1e-6;
    	if ( x + esp < 0.05 && x - esp > -0.05 )
    		return 0.0;
    	else if ( x < 0.0 )
    		return x - esp;
    	else return x;
    	
    }
    
    void calc( double x0, double y0, double x1, double y1, double x2, double y2 )
    {
    	double a  = dist( x0, y0, x1, y1 );
    	double b  = dist( x0, y0, x2, y2 );
    	double c  = dist( x2, y2, x1, y1 );
    	if ( x0 == x1 && y1 == y0 || x0 == x2 && y2 == y0 || x2 == x1 && y1 == y2 ) {
    		printf("There is an infinity of possible locations.
    ");
    		return;
    	}
    	if ( fabs(a-b-c) < 1e-9 || fabs(b-a-c) < 1e-9 || fabs(c-a-b) < 1e-9 ) {
    		printf("There is no possible location.
    ");
    		return;
    	}
    	double A1 = x1-x0,B1 = y1-y0,C1 = x1*x1-x0*x0+y1*y1-y0*y0;
    	double A2 = x2-x0,B2 = y2-y0,C2 = x2*x2-x0*x0+y2*y2-y0*y0;
    	double X  = (B1*C2-B2*C1)/(A1*B2-A2*B1)/-2.0;
    	double Y  = (A2*C1-A1*C2)/(A1*B2-A2*B1)/-2.0;
    	printf("The equidistant location is (%.1lf, %.1lf).
    ",deal(X),deal(Y));
    }
    
    int main()
    {
    	int n;
    	double x1,x2,x3,y1,y2,y3;
    	while ( ~scanf("%d",&n) ) 
    	while ( n -- ) {
    		scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3);
    		calc( x1, y1, x2, y2, x3, y3 );
    	}
    	return 0;
    }
    

  • 相关阅读:
    poj1182 食物链
    poj1611 The Suspects
    poj3436 Computer Factory
    (转) GPG入门教程
    cronolog安装配置
    RHCA-436-4 rhcs conga
    pxe引导gparted live万能分区
    linux下拔号pptp
    GNU parted简略用法
    hostapd故障解决(1.1,2.0,2.2)
  • 原文地址:https://www.cnblogs.com/slgkaifa/p/7379675.html
Copyright © 2020-2023  润新知