POJ 2242 The Circumference of the Circle

题目大意:

        现有多个测例(测例数无上限),每个测例中给定三个不共线点的笛卡尔坐标(实数),求该三点外接圆的周长,题中给定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, 大约

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值