0
点赞
收藏
分享

微信扫一扫

poj--2242--The Circumference of the Circle&&[NYIST 1142&&ZOJ1090]


                                                                                                   The Circumference of the Circle


Time Limit: 1000MS

 

Memory Limit: 65536K

Total Submissions: 7393

 

Accepted: 4557


Description


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


The input 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


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.5 0.0 0.0 0.0 1.0 1.0 1.0 5.0 5.0 5.0 7.0 4.0 6.0 0.0 0.0 -1.0 7.0 7.0 7.0 50.0 50.0 50.0 70.0 40.0 60.0 0.0 0.0 10.0 0.0 20.0 1.0 0.0 -500000.0 500000.0 0.0 0.0 500000.0


Sample Output


3.14 4.44 6.28 31.42 62.83 632.24 3141592.65 海伦公式, 题意: 已知不共线的三点,求这三点构成圆周的周长 法一: 通过这三点可求得三边a,b,c。利用余弦定理求得A的余弦值,再根据圆的性质之一: 一段弧所对圆周角均相等,即可转化到该圆以a为直角边以d为斜边的直角三角形 则d=a/cosA C=PI*d 代码:

#include<iostream>
#include<math.h>
#define PI 3.141592653589793
using namespace std;
int main()
{
double x0,x1,x2,y0,y1,y2,a,b,c,cosA;
while(scanf("%lf%lf%lf%lf%lf%lf",&x0,&y0,&x1,&y1,&x2,&y2)!=EOF)
{
a=sqrt((y0-y1)*(y0-y1)+(x0-x1)*(x0-x1));
b=sqrt((y1-y2)*(y1-y2)+(x1-x2)*(x1-x2));
c=sqrt((y0-y2)*(y0-y2)+(x0-x2)*(x0-x2));
cosA=(b*b+c*c-a*a)/(2*b*c);
printf("%.2lf\n",PI*a/sqrt(1-cosA*cosA));
}
return 0;
}


法二:

利用海伦公式:

#include<cmath>
#include<ctime>
#include<queue>
#include<stack>
#include<string>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
#define Max(a,b) a>b?a:b
#define Min(a,b) a>b?b:a
#define mem(a,b) memset(a,b,sizeof(a))
int dir[4][2]= {{0,-1},{-1,0},{0,1},{1,0}};
int a[10000];
#define maxn 100
const double pi=3.141592653589793;
int main()
{
double x1,y1,x2,y2,x3,y3,a,b,c,st,cir,r,p;
while(cin>>x1>>y1>>x2>>y2>>x3>>y3)
{
a=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
b=sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));
c=sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2));
p=(a+b+c)/2;
st=sqrt(p*(p-a)*(p-b)*(p-c));//三角形面积,海伦公式
r=a*b*c/(4*st);
cir=2*pi*r;
printf("%.2lf\n",cir);
}
return 0;
}



举报

相关推荐

0 条评论