ZOJ 1090 The Circumference of the Circle
题目大意:已知三角形的三个顶点坐标,求其外接圆的周长。
解法:刚看到这道题时,马上拿出草稿纸画图,想推导出重心坐标,然后求出半径,再求周长。可是这个过程太复杂了,写到一半就没有兴致了,还是求助于Google。在Wiki百科找到一个已知三条边长度,求外接三角形周长的算法,diameter = abc/2*(sqrt(s(s-a)(s-b)(s-c)),s=(a+b+c)/2。问题瞬间简化了,求两点距离是很方便的一件事,然后套用这个公式就可以了。
参考代码:
#include<iostream>
#include<iomanip>
#include<cmath>
#define PI 3.141592653589793
using namespace std; double distance(double x1,double y1,double x2,double y2); int main(){
double x1,x2,x3,y1,y2,y3;
double C,d,xx,yy,a,b,c; while(cin>>x1>>y1>>x2>>y2>>x3>>y3){
a=distance(x1,y1,x2,y2);
b=distance(x2,y2,x3,y3);
c=distance(x3,y3,x1,y1);
d=2*a*b*c/(sqrt((a+b+c)*(-a+b+c)*(a-b+c)*(a+b-c)));
C=d*PI;
cout<< fixed << setprecision(2) <<C<<endl;
}
return 0;
} double distance(double x1,double y1,double x2,double y2){
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
} /* en.wikipedia.org/wiki/Circumscribed_circle diameter = abc/2*(sqrt(s(s-a)(s-b)(s-c))
s=(a+b+c)/2 */
ZOJ 1090 The Circumference of the Circle的更多相关文章
- ZOJ Problem Set - 1090——The Circumference of the Circle
ZOJ Problem Set - 1090 The Circumference of the Circle Time Limit: 2 Seconds Memory Limit: 65 ...
- poj 1090:The Circumference of the Circle(计算几何,求三角形外心)
The Circumference of the Circle Time Limit: 2 Seconds Memory Limit: 65536 KB To calculate the c ...
- F - The Circumference of the Circle
Description To calculate the circumference of a circle seems to be an easy task - provided you know ...
- POJ2242 The Circumference of the Circle(几何)
题目链接. 题目大意: 给定三个点,即一个任意三角形,求外接圆的周长. 分析: 外接圆的半径可以通过公式求得(2*r = a/sinA = b/sinB = c/sinC),然后直接求周长. 注意: ...
- 【POJ2242】The Circumference of the Circle(初等几何)
已知三点坐标,算圆面积. 使用初等几何知识,根据海伦公式s = sqrt(p(p - a)(p - b)(p - c)) 和 外接圆直径 d = a * b * c / (2s) 来直接计算. #in ...
- POJ 2242 The Circumference of the Circle
做题回顾:用到海伦公式,还有注意数据类型,最好统一 p=(a+b+c)/2; s=sqrt(p*(p-a)*(p-b)*(p-c));//三角形面积,海伦公式 r=a*b*c/(4*s);//这是外接 ...
- POJ题目细究
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP: 1011 NTA 简单题 1013 Great Equipment 简单题 102 ...
- 【转】POJ百道水题列表
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...
- [Swift]LeetCode478. 在圆内随机生成点 | Generate Random Point in a Circle
Given the radius and x-y positions of the center of a circle, write a function randPoint which gener ...
随机推荐
- Oracle 过程控制语句整理
分支语句/循环语句 v_case ) :; begin then dbms_output.put_line('条件成立'); elsif then then dbms_output.put_line( ...
- CodeForces 468A Program F
Description Little X used to play a card game called "24 Game", but recently he has found ...
- 100个iOS开发/设计面试题汇总
常见问题 你昨天/这周学习了什么? 你为什么热衷于软件开发? 你对哪一种控制系统比较熟悉? 是否参与过GitHub项目? 是否参与过GitHub或其他同类型网站的iOS开源项目? 请描述一下你的iOS ...
- Ogre1.8地形和天空盒的建立(一块地形)
转自:http://www.cnblogs.com/WindyMax/ 研究Ogre的程序笔记 编译环境 WIN7 32 VS2008 Ogre的版本 1.8 Ogre的地形算法是采用Geome ...
- 浅谈Ddos攻击攻击与防御
EMail: jianxin#80sec.comSite: http://www.80sec.comDate: 2011-2-10From: http://www.80sec.com/ [ 目录 ]一 ...
- Ubuntu 14.10 下grep命令详解
简介 grep (global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具,它 ...
- jsCodeWar 多函数嵌套调用
function compose(f, g) { return function() { return f(g.apply(this, arguments)); }; } --- function c ...
- MAT
http://www.yrom.net/blog/2014/08/29/eclipse-mat/
- ios 从网络上获取图片并在UIImageView中显示
ios 从网络上获取图片 -(UIImage *) getImageFromURL:(NSString *)fileURL { NSLog(@"执行图片下载函数"); UIIm ...
- php大力力 [019节]php分页类的学习
2015-08-26 php大力力019.php分页类的学习 [2014]兄弟连高洛峰 PHP教程14.2.1 分页需求分析 14:18 [2014]兄弟连高洛峰 PHP教程14.2.2 分页类中分页 ...