zoukankan      html  css  js  c++  java
  • poj 1329(已知三点求外接圆方程.)

    Circle Through Three Points
    Time Limit: 1000MS   Memory Limit: 10000K
    Total Submissions: 3766   Accepted: 1570

    Description

    Your team is to write a program that, given the Cartesian coordinates of three points on a plane, will find the equation of the circle through them all. The three points will not be on a straight line.
    The solution is to be printed as an equation of the form
    	(x - h)^2 + (y - k)^2 = r^2				(1)

    and an equation of the form
    	x^2 + y^2 + cx + dy - e = 0				(2)

    Input

    Each line of input to your program will contain the x and y coordinates of three points, in the order Ax, Ay, Bx, By, Cx, Cy. These coordinates will be real numbers separated from each other by one or more spaces.

    Output

    Your program must print the required equations on two lines using the format given in the sample below. Your computed values for h, k, r, c, d, and e in Equations 1 and 2 above are to be printed with three digits after the decimal point. Plus and minus signs in the equations should be changed as needed to avoid multiple signs before a number. Plus, minus, and equal signs must be separated from the adjacent characters by a single space on each side. No other spaces are to appear in the equations. Print a single blank line after each equation pair.

    Sample Input

    7.0 -5.0 -1.0 1.0 0.0 -6.0
    1.0 7.0 8.0 6.0 7.0 -2.0
    

    Sample Output

    (x - 3.000)^2 + (y + 2.000)^2 = 5.000^2
    x^2 + y^2 - 6.000x + 4.000y - 12.000 = 0
    
    (x - 3.921)^2 + (y - 2.447)^2 = 5.409^2
    x^2 + y^2 - 7.842x - 4.895y - 7.895 = 0
    

    Source

    恶心的输出..看了discuss才知道0.000要原样输出。。

    #include<stdio.h>
    #include<iostream>
    #include<string.h>
    #include <stdlib.h>
    #include<math.h>
    #include<algorithm>
    using namespace std;
    const double pi =  3.141592653589793;
    const double eps = 1e-8;
    struct Point
    {
        double x,y;
    } p[3];
    double dis(Point a,Point b)
    {
        return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
    }
    ///外接圆圆心坐标
    Point waixin(Point a,Point b,Point c)
    {
        Point p;
        double a1 = b.x - a.x, b1 = b.y - a.y, c1 = (a1*a1 + b1*b1)/2;
        double a2 = c.x - a.x, b2 = c.y - a.y, c2 = (a2*a2 + b2*b2)/2;
        double d = a1*b2 - a2*b1;
        p.x = a.x + (c1*b2 - c2*b1)/d, p.y=a.y + (a1*c2 -a2*c1)/d;
        return p;
    }
    char check(double x)
    {
        if(x<-eps) return '+';
        return '-';
    }
    char check2(double x)
    {
        if(x<-eps) return '-';
        return '+';
    }
    int main()
    {
    
        while(scanf("%lf%lf%lf%lf%lf%lf",&p[0].x,&p[0].y,&p[1].x,&p[1].y,&p[2].x,&p[2].y)!=EOF)
        {
            double a = dis(p[0],p[1]);
            double b = dis(p[1],p[2]);
            double c = dis(p[0],p[2]);
            double r = a*b*c/sqrt((a+b+c)*(-a+b+c)*(a-b+c)*(a+b-c));
            Point center;
            center = waixin(p[0],p[1],p[2]);
            if(fabs(center.x)<eps) printf("x^2 + ");
            else printf("(x %c %.3lf)^2 + ",check(center.x),fabs(center.x));
            if(fabs(center.y)<eps) printf("y^2");
            else printf("(y %c %.3lf)^2",check(center.y),fabs(center.y));
            printf(" = %.3lf^2
    ",r);
    
            printf("x^2 + y^2");
            double c1 = 2*center.x,d1=2*center.y;
            double r1 = center.x*center.x+center.y*center.y-r*r;
            printf(" %c %.3lfx %c %.3lfy %c %.3lf = 0
    
    ",check(c1),fabs(c1),check(d1),fabs(d1),check2(r1),fabs(r1));
        }
        return 0;
    }
  • 相关阅读:
    八、基本数据结构(图形结构)
    七、基本数据结构(树形结构)
    4、使用 ImportTsv 将 Hive 数据导入 Hbase
    六、跳表
    五、二分法查找
    四、归并排序 && 快速排序
    一、kafka 介绍 && kafka-client
    三、排序之冒泡、插入、选择
    二、YARN
    三、synchronized & lock
  • 原文地址:https://www.cnblogs.com/liyinggang/p/5456328.html
Copyright © 2011-2022 走看看