博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 1329 三角外接圆
阅读量:5136 次
发布时间:2019-06-13

本文共 4014 字,大约阅读时间需要 13 分钟。

Circle Through Three Points
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 3169   Accepted: 1342

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.01.0 7.0 8.0 6.0 7.0 -2.0

Sample Output

(x - 3.000)^2 + (y + 2.000)^2 = 5.000^2x^2 + y^2 - 6.000x + 4.000y - 12.000 = 0(x - 3.921)^2 + (y - 2.447)^2 = 5.409^2x^2 + y^2 - 7.842x - 4.895y - 7.895 = 0

给定三个点,求三角形的外接圆,题目非常easy,练一下计算几何的模板代码。输出非常恶心。

代码:

/* ***********************************************Author :rabbitCreated Time :2014/4/19 23:46:03File Name :8.cpp************************************************ */#pragma comment(linker, "/STACK:102400000,102400000")#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;#define INF 0x3f3f3f3f#define eps 1e-8#define pi acos(-1.0)typedef long long ll;int dcmp(double x){ if(fabs(x)
0?

1:-1; } struct Point{ double x,y; Point(double _x=0,double _y=0){ x=_x;y=_y; } }; Point operator + (Point a,Point b){ return Point(a.x+b.x,a.y+b.y); } Point operator - (Point a,Point b){ return Point(a.x-b.x,a.y-b.y); } Point operator * (Point a,double p){ return Point(a.x*p,a.y*p); } Point operator / (Point a,double p){ return Point(a.x/p,a.y/p); } bool operator < (const Point &a,const Point &b){ return a.x<b.x||(a.x==b.x&&a.y<b.y); } bool operator == (const Point &a,const Point &b){ return dcmp(a.x-b.x)==0&&dcmp(a.y-b.y)==0; } double Dot(Point a,Point b){ return a.x*b.x+a.y*b.y; } double Length(Point a){ return sqrt(Dot(a,a)); } struct Circle{ Point c; double r; Circle(){} Circle(Point c,double r):c(c),r(r){} Point point(double a){ return Point(c.x+cos(a)*r,c.y+sin(a)*r); } }; Circle CircumscribedCircle(Point p1,Point p2,Point p3){ double Bx=p2.x-p1.x,By=p2.y-p1.y; double Cx=p3.x-p1.x,Cy=p3.y-p1.y; double D=2*(Bx*Cy-By*Cx); double cx=(Cy*(Bx*Bx+By*By)-By*(Cx*Cx+Cy*Cy))/D+p1.x; double cy=(Bx*(Cx*Cx+Cy*Cy)-Cx*(Bx*Bx+By*By))/D+p1.y; Point p=Point(cx,cy); return Circle(p,Length(p1-p)); } void output(double R, Point P0) { double C; if(P0.x>0)printf("(x - %.3lf)^2 + ",P0.x);else printf("(x + %.3lf)^2 + ",P0.x*(-1)); if(P0.y>0)printf("(y - %.3lf)^2 = %.3f^2\n",P0.y,R);else printf("(y + %.3lf)^2 = %.3f^2\n",P0.y*(-1),R); printf("x^2 + y^2 "); if(P0.x>0)printf("- %.3lfx ",P0.x*2);else printf("+ %.3lfx ",P0.x*(-2)); if(P0.y>0)printf("- %.3lfy ",P0.y*2);else printf("+ %.3lfy ",P0.y*(-2)); C = P0.x*P0.x + P0.y*P0.y - R*R; if(C>0)printf("+ %.3lf = 0\n",C);else printf("- %.3lf = 0\n",C*(-1)); } int main() { //freopen("data.in","r",stdin); //freopen("data.out","w",stdout); Point a,b,c; Circle p; while(cin>>a.x>>a.y>>b.x>>b.y>>c.x>>c.y){ p=CircumscribedCircle(a,b,c); output(p.r,p.c); puts(""); } return 0; }

转载于:https://www.cnblogs.com/hrhguanli/p/5050231.html

你可能感兴趣的文章
软件是天时、地利、人和的产物!
查看>>
python定时清空本目录下除本脚本外的全部文件
查看>>
【PHP】在目标字符串指定位置插入字符串
查看>>
【JS】jQuery设置定时器,访问服务器(PHP示例)配合微信、支付宝原生支付,跳转web网页...
查看>>
实验四2
查看>>
VS2012+Win7网站发布详细步骤
查看>>
Android现学现用第十一天
查看>>
Bin Packing 装箱问题——NPH问题的暴力枚举 状压DP
查看>>
多路复用
查看>>
python 列表
查看>>
Python数据可视化之Pygal(雷达图)
查看>>
当前主流读取Excel技术对比
查看>>
Java学习笔记--字符串和文件IO
查看>>
【BZOJ1951】古代猪文(CRT,卢卡斯定理)
查看>>
poj 2823 线段树
查看>>
转 Silverlight开发历程—(画刷与着色之线性渐变画刷)
查看>>
SQL语法(3)
查看>>
在js在添版本号
查看>>
sublime3
查看>>
CMap的使用(转)
查看>>