zoukankan      html  css  js  c++  java
  • POJ1329题

    Circle Through Three Points

    Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other)
    Total Submission(s) : 35   Accepted Submission(s) : 8
    Problem 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
     

    题意:给你三个圆上的点,求圆的两种表达式。首先普及知识:


    外接圆半径:公式:a/sinA=b/sinB=c/sinC=2R (R就是外接圆半径) 
    本题可以这样:①.先利用余弦定理:a^2=b^2+c^2-2bc·cosA 
    求出:cosA=(b^2+c^2-a^2)/2bc 在利用公式:sinA^2+cosA^2=1
    确定 sinA=根号(1-cosA^2) =根号[(a^2+b^2+c^2)^2-2(a^4+b^4+c^4)]/(2bc) 
    然后代入 a/sinA=2R求出R. R=abc/根号[(a^2+b^2+c^2)^2-2(a^4+b^4+c^4)]        
     
    定义:设平面上的三点A(x1,y1),B(x2,y2),C(x3,y3),定义 
    S(A,B,C) = (x1-x3)*(y2-y3) - (y1-y3)*(x2-x3) 


    已知三角形的三个顶点为A(x1,y1),B(x2,y2),C(x3,y3),则该三角形的外心为: 
               S((x1*x1+y1*y1, y1), (x2*x2+y2*y2, y2), (x3*x3+y3*y3, y3)) 
    x0 = ----------------------------------------------------------- 
                           2*S(A,B,C) 


             S((x1,x1*x1+y1*y1), (x2, x2*x2+y2*y2), (x3, x3*x3+y3*y3)) 
    y0 = ----------------------------------------------------------- 
                2*S(A,B,C) 

    把圆心的坐标和半径求出来之后就输出。

    代码:

    #include<iostream>
    #include<cmath>
    using namespace std;
    double Dist(double x,double y,double x1,double y1)
    {
    return (x-x1)*(x-x1)+(y-y1)*(y-y1);
    }
    double Sn(double x1,double y1,double x2,double y2,double x3,double y3)
    {
    return (x1-x3)*(y2-y3)-(y1-y3)*(x2-x3);
    }
    void Fn(double x)
    {
    if(x<0) printf(" + %.3lf",-x);
    else printf(" - %.3lf",x);
    }
    int main()
    {
    double x1,x2,x3,y1,y2,y3,x,y;
    while( scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3)!=EOF){
    double a=Dist(x1,y1,x2,y2);
    double b=Dist(x2,y2,x3,y3);
    double c=Dist(x3,y3,x1,y1);
    double r=sqrt(a*b*c)/sqrt((a+b+c)*(a+b+c)-2*(a*a+b*b+c*c));
    // printf("%.lf ",r);
    double s=Sn(x1,y1,x2,y2,x3,y3);
    double s1=Sn( x1*x1+y1*y1, y1, x2*x2+y2*y2, y2, x3*x3+y3*y3, y3);
    double s2=Sn( x1,x1*x1+y1*y1, x2, x2*x2+y2*y2, x3, x3*x3+y3*y3);
    x=s1/(2*s);
    y=s2/(2*s);

    printf("(x");
    Fn(x);
    printf(")^2 + (y");
    Fn(y);
    printf(")^2 = %.3lf^2 ",r);
    printf("x^2 + y^2");
    Fn(2*x); printf("x");
    Fn(2*y); printf("y");
    Fn(r*r-x*x-y*y);
    printf(" = 0 ");
    }
    return 0;
    }

  • 相关阅读:
    ABAP方法的exporting类型参数,需要在方法实现最开始显式初始化么
    Hybris里类似ABAP Netweaver的DDIC
    Hybris里类似ABAP Netweaver的DDIC
    SAP Cloud for Customer的CTI呼叫中心解决方案
    如何处理SAP HANA Web-Based Development Workbench的403 Forbidden错误
    Jerry's spark demo application
    SAP CRM WebClient UI和Hybris Commerce里的跨组件跳转
    SAP Cloud for Customer和Hybris Commerce的session保护机制
    SAP ABAP SQL的execution plan和cache
    SAP CRM呼叫中心里的事件注册机制
  • 原文地址:https://www.cnblogs.com/1314wamm/p/4962602.html
Copyright © 2011-2022 走看看