ZOJ 1090 - The Circumference of the Circle 解题报告

      题目的链接在这里:

      http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1090

      题目描述很简单,大意是,给出三个点的坐标,设为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
#include <stdio.h>
#include <math.h>
#define PI 3.141592653589793
#define DISTANCE(x1,y1,x2,y2)  sqrt(((x2)-(x1))*((x2)-(x1))+((y2)-(y1))*((y2)-(y1)))
void main()
{
    double x1, x2, x3, y1, y2, y3;
    double d12, d23, d31, k, result;
    while(scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3)!=EOF)
    {
        d12 = DISTANCE(x1,y1,x2,y2);
        d23 = DISTANCE(x2,y2,x3,y3);
        d31 = DISTANCE(x3,y3,x1,y1);
        k = fabs((y3-y1)*(x2-x1)-(x3-x1)*(y2-y1));
        result=d12*d23*d31/k*PI;
        printf("%.2lf\n",result); 
    }
}

      代码仅有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

         。。。

时间: 2024-09-20 01:06:05

ZOJ 1090 - The Circumference of the Circle 解题报告的相关文章

ZOJ 3505. Yet Another Set of Numbers 解题报告

ZOJ 3505:Yet Another Set of Numbers 地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3505   题意:有一个数字集合,集合中的数遵循以下规则:   ( 1 ). 每个数字的最高位不是 0 ; ( 2 ). 每个数字包含最多 N 位,且只有 0,1,2,3 这四个数字可能出现(0 < N < 20); ( 3 ). 每个数字的相邻位不同(例如:301是有效的,300不是); (

UVa 438 The Circumference of the Circle (计算几何)

438 - The Circumference of the Circle Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=379 To calculate the circumference of a circle seems to be an easy t

POJ 2242 The Circumference of the Circle:计算几何

The Circumference of the Circle http://poj.org/problem?id=2242 Time Limit: 1000MS Memory Limit: 65536K Description To calculate the circumference of a circle seems to be an easy task - provided you know its diameter. But what if you don't? You are gi

杭电ACM 2000-&amp;gt;2099 100道题 详细解题报告出炉

我去年暑假花了5天,把杭电ACM网站上2000到2099这100道题全AC了,又花了10来天精心写解题报告.里面包括题目.解题思路.编程技巧以及参考源码.所有代码都是使用C/C++写的. 最近整理资料时无意间发现,打包成chm文件和大家分享.我已经上传到CSDN上了.下载地址:http://download.csdn.net/source/492194 也可到我的Google Sites上下载. 题号 题名 题号 题名 2000 ASCII码排序 2001 计算两点间的距离 2002 计算球体积

ZOJ 1111 - Poker Hands 解题报告

          Poker Hands (比较两手牌的大小)           http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=111           题目描述:这道题要求比较两手牌的大小.每手牌都有5张牌组成,牌的大小的定义如下,首先确定这组牌的所属种类是下面哪一种(若同属同一种类,则根据该分类后面的比较规则继续比较,所属种类越靠后牌越大).           ● High Card:杂牌(不属于下面任何一种).

ZOJ - 1098 Simple Computer 解题报告

Simple Computers Time Limit: 1 Second      Memory Limit: 32768 KB You are to write an interpreter for a simple computer. This computer uses a processor with a small number of machine instructions. Furthermore, it is equipped with 32 byte of memory, o

ZOJ 2529 - A+B in Hogwarts 解题报告

          题目2529:A+B in Hogwarts           链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1535           题目描述:哈利波特去的魔法学院使用一种特殊进制法表示数字:第i位用第i个素数为进制(radix),例如"个位"的进制为第一个素数2,"十位"的进制为第二个素数3,"百位"的进制为第三个素数5,...依此类推.例

ZOJ 1010. Area 解题报告

ZOJ 1010. Area. 题目地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1010 基本题意:此题目给出 n 个点的坐标 (xi,yi ) ,要求求出这些点按顺序围成的多边形的面积.同时要求检测出不合法的多边形(例如非相邻边彼此相交的情况).     此题求面积不难,样例很容易就过了,但是提交 10+ 次基本都是 WA ,几乎失去信心.做题最郁闷的就是你不知道问题到底出在什么地方,可能改了很多次都没有试对地

ZOJ 1205 - Martian Addition 解题报告

          http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1205           题目说明:(把题目从GOOGLE翻译的结果修改而来)           在22世纪,科学家们发现智能居民生活在火星.火星人非常喜欢数学.每一年,他们将举行一次火星算术大赛(计算机) ,竞赛内容是计算两个100位数的和,使用时间最少的人获得冠军.今年,他们还邀请地球上的人参加竞赛.            作为唯一代表地球,你发