UVa 438 - The Circumference of the Circle

Contents

  1. 1. Problem
  2. 2. Solution
  3. 3. Code

Problem

中文網址

Solution

先算出三個邊,再用 餘弦定理 求出 $cos(A)$ 。
對 $cos(A)$ 取反函數 arc() 後即為 $A$ ,此時再用 正弦定理 將直徑求出即可。

也可用三角形面積 $\frac{1}{2}bcsin(A)$ 和海龍公式,以邊 a 為底在圓上找一點使其成為直角三角形,此時斜邊即為 $2R$ ,$sin(A) = \frac{a}{2R}$ ,代回三角形面積以求出直徑。

Code

UVa 438
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<cstdio>
#include<cmath>

inline double getDis(double x1, double y1, double x2, double y2)
{
return sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
}
int main()
{
double x1, y1, x2, y2, x3, y3, pi = acos(-1);
while (scanf("%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3) != EOF)
{
double a = getDis(x1, y1, x2, y2), b = getDis(x1, y1, x3, y3), c = getDis(x3, y3, x2, y2);
double cosA = (b*b + c*c - a*a) /( 2 * b*c);//餘弦定理
double A = acos(cosA);
double R2 = a / sin(A);//正弦定理

printf("%.2lf\n", R2*pi);
}

return 0;
}