Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 3678 | Accepted: 1542 |
Description
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
Output
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;
}
法二:
#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("- ");