您的位置:首页 > Web前端

HDU 1374 The Circumference of the Circle 计算几何

2016-08-14 17:54 357 查看
题目的链接如下:

http://acm.hdu.edu.cn/showproblem.php?pid=1374

The Circumference of the Circle

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 920 Accepted Submission(s): 685

Problem 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 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

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

完全的模板,求不共线的三点的外接圆。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#define eps 1e-8
#define PI 3.141592653589793
struct Tpoint
{
double x,y;
Tpoint operator-(Tpoint&a){
Tpoint p1;
p1.x=x-a.x;
p1.y=y-a.y;
return p1;
}
};
double dist(Tpoint p1,Tpoint p2) // 返回两点之间欧氏距离
{
return( sqrt( (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y) ) );
}
Tpoint q;//圆心
double r, l;
void cocircle(Tpoint p1,Tpoint p2,Tpoint p3)
{
double x12=p2.x-p1.x;
double y12=p2.y-p1.y;
double x13=p3.x-p1.x;
double y13=p3.y-p1.y;
double z2=x12*(p1.x+p2.x)+y12*(p1.y+p2.y);
double z3=x13*(p1.x+p3.x)+y13*(p1.y+p3.y);
double d=2.0*(x12*(p3.y-p2.y)-y12*(p3.x-p2.x));
q.x=(y13*z2-y12*z3)/d;
q.y=(x12*z3-x13*z2)/d;
r=dist(p1,q);
l = 2 * PI * r;
return ;
}
using namespace std;
int main() {
Tpoint ans;
Tpoint a[10];
while(~scanf("%lf%lf%lf%lf%lf%lf",&a[1].x,&a[1].y,&a[2].x,&a[2].y,&a[3].x,&a[3].y)){
cocircle(a[1], a[2], a[3]);
printf("%.2f\n", l);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  计算几何