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 ...
随机推荐
- Ubuntu14.04安装和配置ROS Indigo(一)
安装ROS 配置Ubuntu的软件源 配置Ubuntu要求允许接受restricted.universe和multiverse的软件源,可以根据下面的链接配置: https://help.ubuntu ...
- oracle数据库常用SQL语句(11.29更新)
笔者日常工作中常用到的sql语句,现总结如下,留作日后查看. 1.按照两列中的最大值取 ,只取两列其中的一列 SELECT * FROM t_doc T ORDER BY GREATEST(T.Loa ...
- web安全 -- 常见攻击方法及预防措施
一.sql注入 sql注入,是指攻击者在猜测出服务器上要执行sql后:通过输入数据,拼接原来要执行的sql而形成新的sql:从而到达改变原来查询的意义的目的. -- 原来sql select xxx ...
- Word2013可以写博客
步骤如下http://www.cnblogs.com/guyichang/p/4629211.html
- [网络技术]网关 路由器 OSI
tracert 1.网关与路由 关键的区别:网关是这样一个网络节点:以两个不同协议搭建的网络可以通过它进行通信.路由器是这样一种设备:它能在计算机网络间收发数据包,同时创建一个覆盖网络(overlay ...
- selectNodes
解析beans.xml的时候有时候找不到节点,把其他多余的删除之后就好了,不知道为什么.
- WEB-INF& 绝对路径vs相对路径
在struts2里面用XXXInput方法和springmvc里面用GET模式进入添加或者登陆输入页面,有时候会在方法里面做一下准备,比如动态读入部门信息放在select中,或者在model中加入一个 ...
- poj2777 线段树
//Accepted 4768 KB 391 ms //线段树,延时标记的应用 //对于每一段,用一个int表示被着色的情况,change标记该段的颜色是否发生整体的改变,即这一段 //用没用被全部涂 ...
- Oracle排序问题
关于oracle排序的几点认识: (1)oracle本身不具有任何默认排序功能,要想排序,必须使用order by,而order by后的数据行默认是asc(升序排列),要降序选择desc : (2) ...
- mahout中kmeans算法和Canopy算法实现原理
本文讲一下mahout中kmeans算法和Canopy算法实现原理. 一. Kmeans是一个很经典的聚类算法,我想大家都非常熟悉.虽然算法较为简单,在实际应用中却可以有不错的效果:其算法原理也决定了 ...