【POJ2242】The Circumference of the Circle(初等几何)

已知三点坐标,算圆面积。

使用初等几何知识,根据海伦公式s = sqrt(p(p - a)(p - b)(p - c)) 和 外接圆直径 d = a * b * c / (2s) 来直接计算。

 

 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdlib>
 4 #include <cstdio>
 5 #include <numeric>
 6 #include <cctype>
 7 #include <cmath>
 8 #include <algorithm>
 9 
10 #define PI acos(-1)
11 using namespace std;
12 
13 double calc_dis (double x1, double y1, double x2, double y2) {
14     return sqrt ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
15 }
16 
17 int main () {
18     ios :: sync_with_stdio(false);
19     double x[3], y[3];
20     while (cin >> x[0] >> y[0]) {
21         for (int i = 1; i < 3; ++ i) {
22             cin >> x[i] >> y[i];
23         }
24         double a, b, c;
25         a = calc_dis (x[0], y[0], x[1], y[1]);
26         b = calc_dis (x[0], y[0], x[2], y[2]);
27         c = calc_dis (x[2], y[2], x[1], y[1]);
28         //cout << a << " " << b << " " << c << endl;
29         double p = (a + b + c) / 2;
30         double s = sqrt (p * (p - a) * (p - b) * (p - c));
31         //cout << "s : " << s << endl;
32         double d = a * b * c / (2 * s);
33         printf ("%.2f\n", PI * d);
34     }
35     return 0;
36 }

 

posted @ 2014-09-20 20:12  Desgard_Duan  阅读(255)  评论(0编辑  收藏  举报