POJ 1329 Circle Through Three Points

Circle Through Three Points

Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 3678   Accepted: 1542

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

#include<stdio.h>
#include<math.h>
struct Node
{
double x,y;
} center;
void Center(double x1,double y1,double x2,double y2,double x3,double y3)
{
double t1,t2,t3,temp;
t1=x1*x1+y1*y1;
t2=x2*x2+y2*y2;
t3=x3*x3+y3*y3;
temp=x1*y2+x2*y3+x3*y1-x1*y3-x2*y1-x3*y2;
center.x=(t2*y3+t1*y2+t3*y1-t2*y1-t3*y2-t1*y3)/temp/2;
center.y=(t3*x2+t2*x1+t1*x3-t1*x2-t2*x3-t3*x1)/temp/2;
}
double d;
void dis(double x1,double y1,double x2,double y2)
{
d=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int main()
{
double x1,y1,x2,y2,x3,y3;
while(scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3)!=EOF)
{
Center(x1,y1,x2,y2,x3,y3);
//printf("%lf %lf\n",center.x,center.y);
dis(center.x,center.y,x1,y1);
//printf("%lf\n",d);
//(x - 3.000)^2 + (y + 2.000)^2 = 5.000^2
printf("(x ");
if(center.x<0)
printf("+ ");
else
printf("- ");
printf("%.3lf)^2 + (y ",fabs(center.x));
if(center.y<0)
printf("+ ");
else
printf("- ");
printf("%.3lf)^2 = ",fabs(center.y));
printf("%.3lf^2\n",d);
//x^2 + y^2 - 6.000x + 4.000y - 12.000 = 0
printf("x^2 + y^2 ");
if(center.x<0)
printf("+ ");
else
printf("- ");
printf("%.3lfx ",2*fabs(center.x));
if(center.y<0)
printf("+ ");
else
printf("- ");
printf("%.3lfy ",2*fabs(center.y));
d=center.x*center.x+center.y*center.y-d*d;
if(d<0)
printf("- ");
else
printf("+ ");
printf("%.3lf ",fabs(d));
printf("= 0\n\n");
}
return 0;
}

时间: 2024-10-19 21:40:29

POJ 1329 Circle Through Three Points的相关文章

POJ 1329 Circle Through Three Points(求三角形的外接圆)

Circle Through Three Points 博客原文地址:http://blog.csdn.net/xuechelingxiao/article/details/40985403 题目大意: 给你三个不共线的三个点的坐标,求出过这三个点的圆的方程.写出方程的两种形式. 解题思路: 其实题目要求写出的方程的形式中包含圆心坐标跟半径,所以说关键问题其实就是求出过三点圆的圆心跟半径就OK了. 其实就是个求三角形外接圆的题目,最后加上一些蛋疼的输出控制就可以了. 代码写的有点麻烦,看到Dis

POJ1329 Circle Through Three Points(三角形外接圆)

题目链接: http://poj.org/problem?id=1329 题目描述: Circle Through Three Points 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 poin

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

POJ 1981 Circle and Points 计算几何

题目大意 给出平面上的一些点,求一个单位圆最多能够覆盖多少点. 思路 数据范围300,但是没有用,多组数据就是要卡O(n3),然而常数优化的比较好的话在POJ能过,但是BZ上还是过不了.我们需要寻找一种O(n2logn)的做法. 做法就是枚举每个点,做一个一这个点为圆心的单位圆.之后将所有在这个圆里的点弄出来,以这些点为圆心做单位圆,与开始的单位圆会产生一段圆弧,最后求哪一段圆弧被覆盖的次数最多就是答案. CODE O(n3)水过版 #define _CRT_SECURE_NO_WARNINGS

POJ 1981 Circle and Points

//对于任意一点已经覆盖了一些点的圆,都可以通过对圆进行偏移,以使其在保证已覆盖的点的基础上,覆盖更多的点 //对这偏移进行到极限,就是刚好使两点在圆上 //其实这题的思路和POJ1106是差不多的,只不过在看到聚会范围在[0,10]的时候想到随机算法去了 //还有一种n^2logn的做法,学习了一下圆上弧被覆盖次数的标记 #include<stdio.h> #include<algorithm> #include<math.h> using namespace std

UVALive 4639 &amp;&amp; SPOJ SPOINTS &amp;&amp; POJ 3805 &amp;&amp; AOJ 1298 Separate Points 求两个凸包是否相交 难度:3

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2640 http://www.spoj.com/problems/SPOINTS/en/ http://poj.org/problem?id=3805 http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1298 要

【POJ】3090 Visible Lattice Points

Visible Lattice Points Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7705   Accepted: 4707 Description A lattice point (x, y) in the first quadrant (x and y are integers greater than or equal to 0), other than the origin, is visible fr

【POJ 3090】 Visible Lattice Points

[题目链接] http://poj.org/problem?id=3090 [算法] 通过观察发现,在这个平面直角坐标系中,除了(1,1),(1,0)和(0,1),所有可见点的横纵坐标互质 那么,问题就转化为了求 2 * (phi(1) + phi(2) + ... + phi(n)) + 3 预处理phi的前缀和,O(1)回答询问,即可 [代码] #include <algorithm> #include <bitset> #include <cctype> #inc

[转] POJ几何分类

转自:http://blog.csdn.net/tyger/article/details/4480029 计算几何题的特点与做题要领:1.大部分不会很难,少部分题目思路很巧妙2.做计算几何题目,模板很重要,模板必须高度可靠.3.要注意代码的组织,因为计算几何的题目很容易上两百行代码,里面大部分是模板.如果代码一片混乱,那么会严重影响做题正确率.4.注意精度控制.5.能用整数的地方尽量用整数,要想到扩大数据的方法(扩大一倍,或扩大sqrt2).因为整数不用考虑浮点误差,而且运算比浮点快. 一.点