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 ...
随机推荐
- POJ 1068 Parencodings 模拟 难度:0
http://poj.org/problem?id=1068 #include<cstdio> #include <cstring> using namespace std; ...
- IT公司100题-11-求二叉树中节点的最大距离
问题描述: 写程序,求一棵二叉树中相距最远的两个节点之间的距离. 10/ \6 14/ \ / \4 8 12 16 分析: 二叉树中最远的两个节点,要么是根 ...
- WP8.1 Study5:Data binding数据绑定
一.数据绑定 最简单的编程UI控件的方法是写自己的数据来获取和设置控件的属性,e.g. , textBox1.Text = "Hello, world"; 但在复杂的应用程序,这样 ...
- Section 1.4 Packing Rectangles
本来是USACO Training的1.4.1的,但是介于今早过了食物链想起了这道题实在是太怨念了,翻出自己写的AC程序居然有5KB!! 思路很简单,枚举,而且就图中的六种情况.但是第六种变化状况太多 ...
- English idioms
a hot potato : speak of an issue(mostly current) which many people are talking about and which is us ...
- 看项目得到info_freeCsdn-01闪屏页面
/** * 渐变展示启动屏 */ private void startAnimation() { Animation aa = new Animation() { }; aa.setDuration( ...
- OBJECT ARX 获取标注样式信息
CString str = _T("标注样式"); CString strTmp(_T("")); ////获得当前图形的标注样式表 AcDbDimStyleT ...
- SMS短信PDU编码
目前,发送短消息常用Text和PDU(Protocol Data Unit,协议数据单元)模式.使用Text模式收发短信代码简单,实现起来十分容易,但最大的缺点是不能收发中文短信:而PDU模式不仅支持 ...
- 【LeetCode OJ】Sum Root to Leaf Numbers
# Definition for a binary tree node # class TreeNode: # def __init__(self, x): # self.val = x # self ...
- centOS5下安装redis make报错
1:/tmp/redis-2.6.14/src/zmalloc.c:223:undefined reference to '__sync_add_and_fetch' make时加参数: make C ...