题目大意:
现有多个测例(测例数无上限),每个测例中给定三个不共线点的笛卡尔坐标(实数),求该三点外接圆的周长,题中给定PI为3.141592653589793,要求输出四舍五入到小数点后两位。
注释代码:
/*
* Problem ID : POJ 2242 The Circumference of the Circle
* Author : Lirx.t.Una
* Language : C
* Run Time : 0 ms
* Run Memory : 172 KB
*/
//两种方法:
//1) c^2 = a^2 + b^2 - 2abcosC
// c / sinC = 2r
// sin^2C + cos^2C = 1
//得 ( c / 2r)^2 + ( ( a^2 + b^2 - c^2 ) / 2ab )^2 = 1
//2) r = abc / 4S
// S = √p(p - a)(p - b)(p - c)
// p = ( a + b + c ) / 2
#include <stdio.h>
#include <math.h>
#define PI 3.141592653589793
#define POW(x) ( (x) * (x) )
int
main() {
double x1, y1;
double x2, y2;
double x3, y3;
double a2, b2, c2;//表示a^2,b^2,c^2
double tmp;//临时变量
while ( ~scanf("%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3) ) {
a2 = POW( x1 - x2 ) + POW( y1 - y2 );
b2 = POW( x1 - x3 ) + POW( y1 - y3 );
c2 = POW( x2 - x3 ) + POW( y2 - y3 );
printf("%.2lf\n", PI * sqrt( c2 / ( 1 - POW( a2 + b2 - c2 ) / ( 4 * a2 * b2 ) ) ));
}
return 0;
}
无注释代码:
#include <stdio.h>
#include <math.h>
#define PI 3.141592653589793
#define POW(x) ( (x) * (x) )
int
main() {
double x1, y1;
double x2, y2;
double x3, y3;
double a2, b2, c2;
double tmp;
while ( ~scanf("%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3) ) {
a2 = POW( x1 - x2 ) + POW( y1 - y2 );
b2 = POW( x1 - x3 ) + POW( y1 - y3 );
c2 = POW( x2 - x3 ) + POW( y2 - y3 );
printf("%.2lf\n", PI * sqrt( c2 / ( 1 - POW( a2 + b2 - c2 ) / ( 4 * a2 * b2 ) ) ));
}
return 0;
}
单词解释:
circumference:n, 圆周,周长
diameter:n, 直径
cartesian:adj, 笛卡尔的(几何)
collinear:adj, 共线的
specification:n, 详述,说明
approximately:adv, 大约