码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-09-20 21:10:29      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   os   使用   for   div   sp   

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

使用初等几何知识,根据海伦公式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 }

 

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

标签:style   blog   color   io   os   使用   for   div   sp   

原文地址:http://www.cnblogs.com/Destiny-Gem/p/3983650.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!