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 ...
随机推荐
- bzoj 1911: [Apio2010]特别行动队
#include<cstdio> #include<iostream> #define M 1000009 #define ll long long using namespa ...
- asp.net后台编写 loading效果
From :http://www.cnblogs.com/ganmk/articles/1207832.html 使用方法: protected void Page_Load(object sende ...
- Andoid activity 生命周期
今天介绍一下Android中最常用的组件activity的生命周期.当activity处于Android应用中运行时,它的活动状态由Android以Activity栈的形式管理.当前活动的Activi ...
- 关于BIOS的一点东西
关于BIOS的一点东西 编辑删除转载2016-05-20 00:36:36 去把BIOS的每个单词意思都有道一遍就都明白了,BOOT是更改 启动顺序的(台式机一直按del键就会进入BIOS界面,用上下 ...
- dom对象操作Html,Css
HTML: 1.不要再文档加载完使用document.write,这样会创建新的dom对象,原来的元素将被覆盖. 2.获取元素,通过getElementbyID; getElementbyTag(&q ...
- SQL Server 2008 定时作业的制定(SQL2005参考此方法) 转
-- Author : htl258(Tony)-- Date : 2010-04-29 19:07:45-- Version:Microsoft SQL Server 2008 (RTM) ...
- JAVA调用系统命令或可执行程序--返回一个Runtime运行时对象,然后启动另外一个进程来执行命令
通过 java.lang.Runtime 类可以方便的调用操作系统命令,或者一个可执行程序,下面的小例子我在windows和linux分别测试过,都通过.基本原理是,首先通过 Runtime.getR ...
- poj1159 dp最长公共子串
//Accepted 204 KB 891 ms //dp最长公共子串 //dp[i][j]=max(dp[i-1][j],dp[i][j-1]) //dp[i][j]=max(dp[i][j],dp ...
- 上位机控制led
使用库函数,调试的结果在标红程序上,int main(void){ u8 a; u8 t; u8 len; u16 ti ...
- MATLAB里的正则表达式 [转]
正则表达式在处理字符串及文本时显得十分方便,在perl, python等脚本语言,以及java, .net等平台上都支援正则表达式.事实上,在MATLAB中也提供了正则表达式的支持.主要包含三个常用的 ...