ZOJ 1090 The Circumference of the Circle(计算三角形的外接圆)
来源:互联网 发布:淘宝装修页尾代码 编辑:程序博客网 时间:2024/05/16 05:43
提交地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1090
这是我最喜欢做的题之一,因为这种题我感觉 做一遍以后就会了,不做心里总是感觉这个地方不会,有点担心。
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 given the cartesian coordinates of three non-collinear points in the plane.
Your job is to calculate the circumference of the unique circle that intersects all three points.
Input Specification
The input file will contain one or more test cases. Each test case consists of one line containing six real numbersx1,y1, x2,y2,x3,y3, representing the coordinates of the three points. The diameter of the circle determined by the three points will never exceed a million. Input is terminated by end of file.Output Specification
For each test case, print one line containing one real number telling the circumference of the circle determined by the three points. The circumference is to be printed accurately rounded to two decimals. The value of pi is approximately 3.141592653589793.Sample Input
0.0 -0.5 0.5 0.0 0.0 0.50.0 0.0 0.0 1.0 1.0 1.05.0 5.0 5.0 7.0 4.0 6.00.0 0.0 -1.0 7.0 7.0 7.050.0 50.0 50.0 70.0 40.0 60.00.0 0.0 10.0 0.0 20.0 1.00.0 -500000.0 500000.0 0.0 0.0 500000.0
Sample Output
3.144.446.2831.4262.83632.243141592.65
先来看看涉及的公式吧!
按照书上来吧:
先看个圆的公式:(x-xo)²+(y-yo)²=r²
已知三点可一代入求得 圆心(xo,yo) 和 半径 r
但是推到公式太复杂。
让我们来换个公式。
已知三点可以求得三条边长a,b,c
sinA/a=sinB/b=sinC/c = 2r
A,B,C为角;
c²=a²+b²-2abcosC
sinC²+cosC²=1
由这些公式就能推到了
sinC²=(c/2r)²
cosC²=((a²+b²-c²)/2ab)²
#include<iostream>#include<stdio.h>#include<math.h>#define PI 3.141592653589793using namespace std;int main(){double x1,y1,x2,y2,x3,y3;while(cin>>x1>>y1>>x2>>y2>>x3>>y3){double af = (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);double bf = (x1-x3)*(x1-x3)+(y1-y3)*(y1-y3);double cf = (x2-x3)*(x2-x3)+(y2-y3)*(y2-y3);double left =(af+bf-cf)*(af+bf-cf)/(4*af*bf);double sinc2=1-left;double r = sqrt(cf/sinc2/4);printf("%.2lf\n",r*PI*2);}}
这些代码就足够了,我的af,bf,cf等是a的平方,b的平方,c的平方。自己推导一下 就出来了,平方太多别乱了 我刚做的时候就乱了,不出结果,浪费了很长时间。
下面再说下一个公式:
三角形外接圆半径为r=abc/4s;
根据海伦公式计算面积:s=sqrt(p(p-a)(p-b)(p-c)) 其中 p=(a+b+c)/2;
这个公式同样可以推到出来。
好了!
感谢自己坚持!
- ZOJ 1090 The Circumference of the Circle(计算三角形的外接圆)
- ZOJ-1090-The Circumference of the Circle(计算几何,海伦公式,三角形外接圆半径公式,cout输出小数的一些问题)
- POJ2242_The Circumference of the Circle(几何/三角形外接圆周长/模板)
- zoj 1090 The Circumference of the Circle
- zoj 1090 The Circumference of the Circle
- ZOJ 1090-The Circumference of the Circle
- HDOJ 1374 The Circumference of the Circle (求外接圆)
- zoj 1090 || poj 2242 The Circumference of the Circle
- php - zoj 1090 The Circumference of the Circle
- TOJ 1132 ZOJ 1090 The Circumference of the Circle
- POJ 2242|ZOJ 1090 The Circumference of the Circle
- 计算几何 The Circumference of the Circle
- The Circumference of the Circle(计算几何)
- zoj 1090 The Circumference of the Circle(海伦公式+正弦定理)
- The Circumference of the Circle
- (DS1.5.6)POJ 2242 The Circumference of the Circle(一直三个点的坐标,求外接圆的周长)
- POJ 2242 The Circumference of the Circle (计算几何)
- UVa 438 The Circumference of the Circle (计算几何)
- 百万数据查询优化技巧三十则
- Go语言 几个亟待解决的Go语言问题
- 【LeetCode】Trapping Rain Water
- C 学习记录 出错记录
- How to Codesign Growl.framework for Sandboxed Mac App
- ZOJ 1090 The Circumference of the Circle(计算三角形的外接圆)
- 用kali生成密钥
- More Effective C++ 读书摘要(auto_ptr的一个实现)
- [android] cocos2d to android game interface
- 面试题:统计给定位串中1的个数
- DATAGUARD在做SWITCHOVER切换时遇到问题总结
- Rational Rose2003 破解 win7
- ViewPager+Fragment的结合使用,实现QQ界面的理解
- 信息资源管理总结