zoukankan      html  css  js  c++  java
  • POJ

    Circle Through Three Points
    Time Limit: 1000MS   Memory Limit: 10000K
    Total Submissions: 4112   Accepted: 1712

    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
    直接推公式计算,推导时细心些,不然debug很累。。
    #include<stdio.h>
    #include<math.h>
    int main()
    {
    	double x1,x2,x3,y1,y2,y3;
    	while (~scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3))
    	{
    		double R;
    		double x, y;
    		double A1 = (x1+x2)/2, B1 = (y1+y2)/2, C1 = (x2-x1)/(y1-y2),
    			A2 = (x2+x3)/2, B2 = (y2+y3)/2, C2 = (x3-x2)/(y2-y3);
    		x = (B2-B1+A1*C1-A2*C2)/(C1-C2);
    		y = C1*(x-A1)+B1;
    		R = sqrt((x1 - x)*(x1 - x) + (y1 - y)*(y1 - y));
    
    		if (x>0)printf("(x - %.3lf)^2 + ", x); else printf("(x + %.3lf)^2 + ", x*(-1));
    		if (y>0)printf("(y - %.3lf)^2 = %.3f^2
    ", y, R); else printf("(y + %.3lf)^2 = %.3f^2
    ", y*(-1), R);
    		printf("x^2 + y^2 ");
    		if (x>0)printf("- %.3lfx ",x * 2); else  printf("+ %.3lfx ", x*(-2));
    		if (y>0)printf("- %.3lfy ",y * 2); else printf("+ %.3lfy ", y*(-2));
    		double M = x*x + y*y - R*R;
    		if (M>0)printf("+ %.3lf = 0
    
    ", M); else  printf("- %.3lf = 0
    
    ", M*(-1));
    
    		//puts("");
    	}
    	return 0;
    }

    
                
    
  • 相关阅读:
    心态--编程+成长
    【Oracle】容易犯的错误和技巧集合
    【WPF】DataGrid的Row样式设置
    【WPF】给TextBox添上Label
    【Oracle】异常信息的加工处理
    【.Net 】Json和Xml解析
    【Win32 API】利用SendMessage实现winform与wpf之间的消息传递
    【WCF】利用WCF实现上传下载文件服务
    【Oracle】实现Oracle数据库对象的一键升级
    感触
  • 原文地址:https://www.cnblogs.com/csu-lmw/p/9124479.html
Copyright © 2011-2022 走看看