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

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

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

 #include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <numeric>
#include <cctype>
#include <cmath>
#include <algorithm> #define PI acos(-1)
using namespace std; double calc_dis (double x1, double y1, double x2, double y2) {
return sqrt ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
} int main () {
ios :: sync_with_stdio(false);
double x[], y[];
while (cin >> x[] >> y[]) {
for (int i = ; i < ; ++ i) {
cin >> x[i] >> y[i];
}
double a, b, c;
a = calc_dis (x[], y[], x[], y[]);
b = calc_dis (x[], y[], x[], y[]);
c = calc_dis (x[], y[], x[], y[]);
//cout << a << " " << b << " " << c << endl;
double p = (a + b + c) / ;
double s = sqrt (p * (p - a) * (p - b) * (p - c));
//cout << "s : " << s << endl;
double d = a * b * c / ( * s);
printf ("%.2f\n", PI * d);
}
return ;
}
上一篇:RUBY类特性


下一篇:11gR2 Database Services for "Policy" and "Administrator" Managed Databases (文件 ID 1481647.1)