Circle Through Three Points

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other)
Total Submission(s) : 35   Accepted Submission(s) : 8
Problem Description
Your team is to write a program that, given the Cartesian coordinates of three points on a plane, will find the equation of the circle through them all. The three points will not be on a straight line. 
The solution is to be printed as an equation of the form

	(x - h)^2 + (y - k)^2 = r^2				(1)

and an equation of the form

	x^2 + y^2 + cx + dy - e = 0				(2)
 
Input
Each line of input to your program will contain the x and y coordinates of three points, in the order Ax, Ay, Bx, By, Cx, Cy. These coordinates will be real numbers separated from each other by one or more spaces.
 
Output
Your program must print the required equations on two lines using the format given in the sample below. Your computed values for h, k, r, c, d, and e in Equations 1 and 2 above are to be printed with three digits after the decimal point. Plus and minus signs in the equations should be changed as needed to avoid multiple signs before a number. Plus, minus, and equal signs must be separated from the adjacent characters by a single space on each side. No other spaces are to appear in the equations. Print a single blank line after each equation pair.
 
Sample Input
7.0 -5.0 -1.0 1.0 0.0 -6.0 1.0 7.0 8.0 6.0 7.0 -2.0
 
Sample Output
(x - 3.000)^2 + (y + 2.000)^2 = 5.000^2 x^2 + y^2 - 6.000x + 4.000y - 12.000 = 0 (x - 3.921)^2 + (y - 2.447)^2 = 5.409^2 x^2 + y^2 - 7.842x - 4.895y - 7.895 = 0

题意:给你三个圆上的点,求圆的两种表达式。首先普及知识:

外接圆半径:公式:a/sinA=b/sinB=c/sinC=2R (R就是外接圆半径) 
本题可以这样:①.先利用余弦定理:a^2=b^2+c^2-2bc·cosA 
求出:cosA=(b^2+c^2-a^2)/2bc 在利用公式:sinA^2+cosA^2=1
确定 sinA=根号(1-cosA^2) =根号[(a^2+b^2+c^2)^2-2(a^4+b^4+c^4)]/(2bc) 
然后代入 a/sinA=2R求出R. R=abc/根号[(a^2+b^2+c^2)^2-2(a^4+b^4+c^4)]        
 
定义:设平面上的三点A(x1,y1),B(x2,y2),C(x3,y3),定义 
S(A,B,C) = (x1-x3)*(y2-y3) - (y1-y3)*(x2-x3)

已知三角形的三个顶点为A(x1,y1),B(x2,y2),C(x3,y3),则该三角形的外心为: 
           S((x1*x1+y1*y1, y1), (x2*x2+y2*y2, y2), (x3*x3+y3*y3, y3)) 
x0 = ----------------------------------------------------------- 
                       2*S(A,B,C)

S((x1,x1*x1+y1*y1), (x2, x2*x2+y2*y2), (x3, x3*x3+y3*y3)) 
y0 = ----------------------------------------------------------- 
            2*S(A,B,C)

把圆心的坐标和半径求出来之后就输出。

代码:

#include<iostream>
#include<cmath>
using namespace std;
double Dist(double x,double y,double x1,double y1)
{
return (x-x1)*(x-x1)+(y-y1)*(y-y1);
}
double Sn(double x1,double y1,double x2,double y2,double x3,double y3)
{
return (x1-x3)*(y2-y3)-(y1-y3)*(x2-x3);
}
void Fn(double x)
{
if(x<0) printf(" + %.3lf",-x);
else printf(" - %.3lf",x);
}
int main()
{
double x1,x2,x3,y1,y2,y3,x,y;
while( scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3)!=EOF){
double a=Dist(x1,y1,x2,y2);
double b=Dist(x2,y2,x3,y3);
double c=Dist(x3,y3,x1,y1);
double r=sqrt(a*b*c)/sqrt((a+b+c)*(a+b+c)-2*(a*a+b*b+c*c));
// printf("%.lf\n",r);
double s=Sn(x1,y1,x2,y2,x3,y3);
double s1=Sn( x1*x1+y1*y1, y1, x2*x2+y2*y2, y2, x3*x3+y3*y3, y3);
double s2=Sn( x1,x1*x1+y1*y1, x2, x2*x2+y2*y2, x3, x3*x3+y3*y3);
x=s1/(2*s);
y=s2/(2*s);

printf("(x");
Fn(x);
printf(")^2 + (y");
Fn(y);
printf(")^2 = %.3lf^2\n",r);
printf("x^2 + y^2");
Fn(2*x); printf("x");
Fn(2*y); printf("y");
Fn(r*r-x*x-y*y);
printf(" = 0\n\n");
}
return 0;
}

POJ1329题的更多相关文章

  1. java基础集合经典训练题

    第一题:要求产生10个随机的字符串,每一个字符串互相不重复,每一个字符串中组成的字符(a-zA-Z0-9)也不相同,每个字符串长度为10; 分析:*1.看到这个题目,或许你脑海中会想到很多方法,比如判 ...

  2. 【Java每日一题】20170106

    20170105问题解析请点击今日问题下方的"[Java每日一题]20170106"查看(问题解析在公众号首发,公众号ID:weknow619) package Jan2017; ...

  3. 【Java每日一题】20170105

    20170104问题解析请点击今日问题下方的"[Java每日一题]20170105"查看(问题解析在公众号首发,公众号ID:weknow619) package Jan2017; ...

  4. 【Java每日一题】20170104

    20170103问题解析请点击今日问题下方的"[Java每日一题]20170104"查看(问题解析在公众号首发,公众号ID:weknow619) package Jan2017; ...

  5. 【Java每日一题】20170103

    20161230问题解析请点击今日问题下方的"[Java每日一题]20170103"查看(问题解析在公众号首发,公众号ID:weknow619) package Jan2017; ...

  6. SQL面试笔试经典题(Part 1)

    本文是在Cat Qi的原贴的基础之上,经本人逐题分别在MySql数据库中实现的笔记,持续更新... 参考原贴:http://www.cnblogs.com/qixuejia/p/3637735.htm ...

  7. 刷LeetCode的正确姿势——第1、125题

    最近刷LeetCode比较频繁,就购买了官方的参考电子书 (CleanCodeHandbook),里面有题目的解析和范例源代码,可以省去非常多寻找免费经验分享内容和整理这些资料的时间.惊喜的是,里面的 ...

  8. AWS的SysOps认证考试样题解析

    刚考过了AWS的developer认证,顺手做了一下SysOps的样题.以下是题目和答案. When working with Amazon RDS, by default AWS is respon ...

  9. AWS开发人员认证考试样题解析

    最近在准备AWS的开发人员考试认证.所以特意做了一下考试样题.每道题尽量给出了文档出处以及解析. Which of the following statements about SQS is true ...

随机推荐

  1. Hadoop家族学习路线图

    主要介绍Hadoop家族产品,常用的项目包括Hadoop, Hive, Pig, HBase, Sqoop, Mahout, Zookeeper, Avro, Ambari, Chukwa,新增加的项 ...

  2. POJ 2253 Frogger(最小生成树)

    青蛙跳跃,题意大概是:青蛙从起点到终点进行一次或多次的跳跃,多次跳跃中肯定有最大的跳跃距离.求在所有的跳跃中,最小的最大跳跃距离SF-_-(不理解?看题目吧). 可以用最小生成树完成.以起点为根,生成 ...

  3. 用PowerShell批量部署wsp包

    转:http://www.xuebuyuan.com/168337.html 提供wsp部署的参数: $wsppath:wsp文件所在的路径,如"c:\" $wspnames:路径 ...

  4. 彻底解决:请求被中止: 未能创建 SSL/TLS 安全通道

    最近有个项目要调用客户用java写的带https的webservice,对方提供了证书文件 test.pfx,我这里调用方式如下: //webservice代理类 SvcService svc = n ...

  5. linux 系统获取网络ip, mask, gateway, dns信息小程序

    net_util.c #define WIRED_DEV                   "eth0"     #define WIRELESS_DEV             ...

  6. By类的使用

     举例,页面上有5个table,每个table都有标题栏和内容栏你觉的我是把每个table的标题都放到List里面遍历使用还是现指定table,在获取table的标题栏使用呢明显后面的方便不容易乱麽所 ...

  7. Linux Kernel Schduler History And Centos7.2's Kernel Resource Analysis

    本文分为概述.历史.el7.2代码架构图解三部分. 解决的问题: a.Kernel调度发展过程: b.以架构图的方式,详解el7.2具体调度实现.内核线程模型.调度时间片计算,以及探究整个Kernel ...

  8. lru cache java

    http://www.acmerblog.com/leetcode-lru-cache-lru-5745.html acm之家的讲解是在是好,丰富 import java.util.LinkedHas ...

  9. 使用C#模拟ASP.NET页面中按钮点击

    c# 模拟Asp.net页面中的某个按钮的点击,向web服务器发出请求 主要就组织要提交的数据,然后以post方式提交. 假设我们有如下的网页 1 <% @ Page Language = &q ...

  10. iLearning D3.js 2.0 released

    There are some great changes in 2.0 version. Console in tutorial: In previous version, there will be ...