2007-04-09
JOJ ACM 1184
To calculate the circumference of a circle seems to be an easy task - provided you know its diameter. But what if you don't?
You are given the cartesian coordinates of three non-collinear points in the plane.
Your job is to calculate the circumference of the unique circle that intersects all three points.
Input Specification
The input file will contain one or more test cases. Each test case consists of one line containing six real numbers x1,y1, x2,y2,x3,y3, representing the coordinates of the three points. The diameter of the circle determined by the three points will never exceed a million. Input is terminated by end of file.
Output Specification
For each test case, print one line containing one real number telling the circumference of the circle determined by the three points. The circumference is to be printed accurately rounded to two decimals. The value of pi is approximately 3.141592653589793.
Sample Input
0.0 -0.5 0.5 0.0 0.0 0.50.0 0.0 0.0 1.0 1.0 1.05.0 5.0 5.0 7.0 4.0 6.00.0 0.0 -1.0 7.0 7.0 7.050.0 50.0 50.0 70.0 40.0 60.00.0 0.0 10.0 0.0 20.0 1.00.0 -500000.0 500000.0 0.0 0.0 500000.0
Sample Output
3.144.446.2831.4262.83632.243141592.65
code:
You are given the cartesian coordinates of three non-collinear points in the plane.
Your job is to calculate the circumference of the unique circle that intersects all three points.
Input Specification
The input file will contain one or more test cases. Each test case consists of one line containing six real numbers x1,y1, x2,y2,x3,y3, representing the coordinates of the three points. The diameter of the circle determined by the three points will never exceed a million. Input is terminated by end of file.
Output Specification
For each test case, print one line containing one real number telling the circumference of the circle determined by the three points. The circumference is to be printed accurately rounded to two decimals. The value of pi is approximately 3.141592653589793.
Sample Input
0.0 -0.5 0.5 0.0 0.0 0.50.0 0.0 0.0 1.0 1.0 1.05.0 5.0 5.0 7.0 4.0 6.00.0 0.0 -1.0 7.0 7.0 7.050.0 50.0 50.0 70.0 40.0 60.00.0 0.0 10.0 0.0 20.0 1.00.0 -500000.0 500000.0 0.0 0.0 500000.0
Sample Output
3.144.446.2831.4262.83632.243141592.65
code:
#include<stdio.h>
#include<math.h>
struct Point{
double x;
double y;
}a[3];
double SinA(){
double dist,high;
double A,B,C;
A = a[0].y-a[1].y;
B = a[1].x-a[0].x;
C = a[0].x*a[1].y-a[1].x*a[0].y;
high = fabs(A*a[2].x+B*a[2].y+C)/sqrt(A*A+B*B);
dist = sqrt(pow((a[0].x - a[2].x),2)+pow(a[0].y-a[2].y,2));
return high/dist;
}
int main(){
double c,ab;
while(scanf("%lf%lf%lf%lf%lf%lf",&a[0].x,&a[0].y,&a[1].x,&a[1].y,&a[2].x,&a[2].y)!=EOF){
ab = sqrt(pow((a[1].x - a[2].x),2)+pow(a[1].y-a[2].y,2));
c = ab * 3.141592653589793 / SinA();
printf("%.2lf\n",c);
}
return 0;
}
发表评论
- 浏览: 71840 次
- 性别:

- 来自: 长春

- 详细资料
搜索本博客
我的相册
spy
共 7 张
共 7 张
最近加入圈子
链接
最新评论
-
明天回家,也盘点一下这学 ...
貌似很充实的。。。向你学习。。
-- by wangshu3000 -
学SSH2时写的入门例子
谢谢,楼主是大好人啊!
-- by zzqLivecn -
对以前扫雷游戏功能进一步 ...
这是我大二的时候写的,代码写的比较烂
-- by fuliang -
对以前扫雷游戏功能进一步 ...
希望你继续完善,不能一边写着那些模式和原则,一边写着这样的代码哦。过几天我再来看 ...
-- by healer_kx -
放假了,n长时间没有用过c+ ...
其实我想评价你其他的C++文章。
-- by healer_kx






评论排行榜