题目的链接在这里:
题目描述很简单,大意是,给出三个点的坐标,设为A(x1,y1),B (x2, y2),C (x3, y3),然后求出通过这三点的圆的周长(保留两位小数)。但推导公式却比较麻烦,我是这样来做的。
首先根据同一个弦的圆心角角度相同,不难得出,圆周的直径d= BC/ sin a = AC/ sin b = AB/sin c;
因此求圆周长= BC / sin (a) *PI;
其中BC为角a的对边长度= sqrt ( (x2-x3)^2 + (y2-y3)^2);
至于sin (a),我们必须通过三点坐标来算,比较麻烦一些,可以利用三角函数的公式:
sin (a)=sin (a1-a2)=sin (a1)cos(a2)-cos(a1)sin(a2);
其中a1和a2分别为射线AC和射线AB和x轴的夹角。如果B,C点都在第一象限,显然有
sin(a1)=(y3-y1)/AC;
cos(a1)=(x3-x1)/AC;
sin(a2)=(x2-x1)/AB;
cos(a2)=(y2-y1)/AB;
化简上式:
周长= BC / sin (a) * PI =( AC*AB*BC ) / ( (y3-y1)(x2-x1)-(x3-x1)(y2-y1) ) * PI;
因此,我们就可以写出如下代码 ( IN C ) :
The Circumference of the Circle
代码仅有18行,并且一次性顺利的AC了,并且发现我的解居然是所有解中排名第一的,呵呵,额外的惊喜。
AC | WA | PE | FPE | SF | TLE | MLE | CE | Total |
1926(54%) | 864(24%) | 8(0%) | 1(0%) | 85(2%) | 275(7%) | 0(0%) | 354(10%) | 3517 |
Top Submssions by Run Time
Submit Time | Language | Run Time(ms) | Run Memory(KB) | User Name |
2008-10-15 21:49:18 | C | 0 | 160 | hoodlum1980 |
2008-10-16 17:35:10 | C | 0 | 160 | angel |
2008-10-03 16:58:56 | C++ | 0 | 176 | xxhhtt |
2008-10-03 21:35:18 | C++ | 0 | 176 | mart0258 |
2008-10-07 15:21:35 | C++ | 0 | 176 | Rorro |
2008-10-09 13:14:03 | C++ | 0 | 176 | missing08 |
2008-10-15 02:34:20 | C++ | 0 | 176 | watashi@Zodiac |
2008-10-15 02:54:43 | C++ | 0 | 176 | watashi@Zodiac |
2008-10-15 03:02:27 | C++ | 0 | 176 | watashi@Zodiac |
2008-10-03 17:48:05 | C++ | 0 | 184 | lizhen |
。。。