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 ...
随机推荐
- 第一个servlet小例子
1.sendForward.jsp <%@ page language="java" contentType="text/html; charset=UTF-8&q ...
- 记一个有想法却没能力实现的硬件产品——mp3校时闹钟
枕头旁的闹钟,我想大家都用过,很便宜.用一节干电池供电.但其最大的缺点就是不太准,不能校时. 电池啥事用光,也不知道.钟是走的很慢,没按时闹,搞的自己迟了到. 于是就有了我的漫长思考过程... 先说手 ...
- Fix the Can’t clobber writable file error in Perforce Version Control System - forward
http://easyprograming.com/eclipse-articles/57-fix-the-cant-clobber-writable-file-error-in-perforce-v ...
- java面试题之ssh
1.写出你熟悉的开源框架以及各自的作用(项目中为什么使用SSH) 答:框架:hibernate,spring,struts1/struts2. Hibernate主要用于数据持久化:封装了JDBC操作 ...
- cpio的简单使用
有如下文件 # file boot.kylin boot.kylin: ASCII cpio archive (SVR4 with no CRC) extract: # cpio -i <boo ...
- 通过使用ScriptManager.RegisterStartupScript,呈现后台多次使用alert方法
在前台HTML中加入alert或者confirm,相信大家已经非常熟悉并且经常使用: <div onclick="alert('hello')">按钮1</div ...
- Java运算符及顺序、选择结构
:运算符(掌握) ()算术运算符 A:+,-,*,/,%,++,-- B:+的用法 a:加法 b:正号 c:字符串连接符 C:/和%的区别 数据做除法操作的时候,/取得是商,%取得是余数 D:++和- ...
- 《Java中方法的参数传递方式只有一种:值传递》
//方法的参数传递机制(1):基本类型做形参的传递. class PrimitiveTransferTest { public static void swap(int a,int b) { //下面 ...
- 《CheckboxDemo.java》
import java.awt.*; import java.applet.Applet; public class CheckboxDemo extends Applet { String Uni[ ...
- Android IPC(inter-process Communitcation)
Android IPC(inter-process Communitcation) http://www.cnblogs.com/imlucky/archive/2013/08/08/3246013. ...