poj1329——求三角形的外接圆(注意格式)

题目链接:

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

题目翻译:

zjh捡到了3个点,他想用这三个点围成一个⚪,给出这三个点的笛卡尔坐标,用这两种表达式,保证不在同一条直线上。
(x - h)^2 + (y - k)^2 = r^2 h,k,r为常数

x^2 + y^2 + ax + by - z = 0 a,b,z为常数

Input

多组数据。
每行三个点,坐标为实数 -10^9<坐标<10^9

Output

两种表达式

给你三个点,求这三个点构成的三角形的外接圆,注意输出格式(运算符号之间有空格!!!)

其他就是模板了。

#include<iostream>
#include<cmath>
using namespace std;
struct Point{
	double x,y;
	Point(double x=0,double y=0):x(x),y(y){}
}p1,p2,p3;
struct Circle{
    Point c;
    double r;
    Circle(Point c, double r):c(c), r(r) {}
    Point point(double a){//通过圆心角求坐标
        return Point(c.x + cos(a)*r, c.y + sin(a)*r);
    }
};
typedef Point Vector;
Vector operator - (Point A, Point B){
    return Vector(A.x-B.x, A.y-B.y);
}
double Dot(Vector A, Vector B){
    return A.x*B.x + A.y*B.y;
}
double Length(Vector A){
    return sqrt(Dot(A, A));
}
Circle CircumscribedCircle(Point p1,Point p2,Point p3){
	double Bx=p2.x-p1.x,By=p2.y-p1.y;
	double Cx=p3.x-p1.x,Cy=p3.y-p1.y;
	double D=2*(Bx*Cy-By*Cx);
	double cx=(Cy*(Bx*Bx+By*By)-By*(Cx*Cx+Cy*Cy))/D+p1.x;
	double cy=(Bx*(Cx*Cx+Cy*Cy)-Cx*(Bx*Bx+By*By))/D+p1.y;
	Point p=Point(cx,cy);
	return Circle(p,Length(p1-p));
}
int main(){
	while(~scanf("%lf%lf%lf%lf%lf%lf",&p1.x,&p1.y,&p2.x,&p2.y,&p3.x,&p3.y)){
		Circle C=CircumscribedCircle(p1,p2,p3);
		double x=C.c.x;
		double y=C.c.y;
		double r=C.r;
		printf("(x ");
		if(x<0) printf("+ %.3f)^2 + (y ",-x);
		else printf("- %.3f)^2 + (y ",x);
		if(y<0) printf("+ %.3f)^2 = %.3f^2",-y,r);
		else printf("- %.3f)^2 = %.3f^2",y,r);
		printf("\n");
		
		printf("x^2 + y^2");
		if(x<0) printf(" + %.3fx",2*(-x));
		else printf(" - %.3fx",2*x);
		if(y<0) printf(" + %.3fy",2*(-y));
		else printf(" - %.3fy",2*y);
		double ans=x*x+y*y-r*r;
		if(ans<0) printf(" - %.3f = 0",-ans);
		else printf(" + %.3f = 0",ans);
		printf("\n");
		printf("\n");
	}
	return 0;
} 

 

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值