POJ 1329 Circle Through Three Points(三角形外接圆)
题目链接:http://poj.org/problem?id=1329
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
const double eps = 1e-;
int sgn(double x)
{
if(fabs(x) < eps) return ;
else return x < ? - : ;
}
struct Point{
double x, y;
Point(){}
Point(double _x, double _y){
x = _x, y = _y;
}
bool operator == (Point b) const{
return sgn(x - b.x) == && sgn(y - b.y) == ;
}
bool operator < (Point b)const{
return sgn(x - b.x) == ? sgn(y - b.y < ) : x < b.x;
}
Point operator - (const Point &b)const{
return Point(x - b.x, y - b.y);
}
//叉积
double operator ^(const Point &b){
return x * b.y - y * b.x;
}
//点积
double operator *(const Point &b){
return x * b.x + y * b.y;
}
double len(){
return hypot(x, y);
}
double len2(){
return x * x + y * y;
}
double distant(Point p){
return hypot(x - p.x, y - p.y);
}
Point operator + (const Point &b)const{
return Point (x + b.x, y + b.y);
}
Point operator * (const double &k)const{
return Point(x * k, y * k);
}
Point operator / (const double &k)const{
return Point(x / k, y / k);
}
//逆时针旋转90度
Point rotleft(){
return Point(- y, x);
}
//顺时针旋转90度
Point rotright(){
return Point(y, -x);
}
};
struct Line{
Point s, e;
Line(){}
Line(Point _s, Point _e){s = _s, e = _e;}
Point crosspoint(Line v){
double a1 = (v.e - v.s)^(s - v.s);
double a2 = (v.e - v.s)^(e - v.s);
return Point((s.x*a2 - e.x*a1)/(a2 - a1),(s.y*a2 - e.y*a1)/(a2 - a1));
}
};
struct circle{
Point p;
double r;
circle(){}
circle(Point _p, double _r){
p = _p, r = _r;
}
circle(double x, double y, double _r){
p = Point(x, y);
r = _r;
}
//三角形外接圆
circle(Point a, Point b, Point c){
Line u = Line( (a + b) / ,((a + b) / ) + ((b - a).rotleft()) );
Line v = Line( (b + c) / ,((b + c) / ) + ((c - b).rotleft()) );
p = u.crosspoint(v);
r = p.distant(a);
}
};
void print(double num) {
if (sgn(num) < ) {
printf("- "); num = -num;
}
else printf("+ ");
printf("%.3f", num);
}
int main()
{
double x1, x2, x3, y1, y2, y3;
while(~scanf("%lf%lf%lf%lf%lf%lf",&x1, &y1, &x2, &y2, &x3, &y3))
{
circle a = circle(Point(x1, y1), Point(x2, y2), Point(x3, y3));
double c = a.r * a.r - (a.p.x * a.p.x + a.p.y * a.p.y);
if (sgn(a.p.x) == )printf("x^2");
else { printf("(x "); print(-a.p.x); printf(")^2"); }
printf(" + ");
if (sgn(a.p.y) == )printf("y^2");
else { printf("(y "); print(-a.p.y); printf(")^2"); }
printf(" = %.3f^2\n", a.r);
printf("x^2 + y^2 ");
print(-a.p.x * 2.0);
printf("x ");
print(-a.p.y * 2.0);
printf("y ");
print(-c);
printf(" = 0\n");
printf("\n");
}
return ;
}
POJ 1329 Circle Through Three Points(三角形外接圆)的更多相关文章
- POJ 1329 Circle Through Three Points(三角形外心)
题目链接 抄的外心模版.然后,输出认真一点.1Y. #include <cstdio> #include <cstring> #include <string> # ...
- POJ - 1329 Circle Through Three Points 求圆
Circle Through Three Points Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4112 Acce ...
- poj 1329 Circle Through Three Points(求圆心+输出)
题目链接:http://poj.org/problem?id=1329 输出很蛋疼,要考虑系数为0,输出也不同 #include<cstdio> #include<cstring&g ...
- ●POJ 1329 Circle Through Three Points
题链: http://poj.org/problem?id=1329 题解: 计算几何,求过不共线的三点的圆 就是用向量暴力算出来的东西... (设出外心M的坐标,由于$|\vec{MA}|=|\ve ...
- poj1329Circle Through Three Points(三角形外接圆)
链接 套模板 不知道有没有x,y=0情况,不过这种情况都按+号输出的. #include <iostream> #include<cstdio> #include<cst ...
- POJ 1329
三角外接圆
Circle Through Three Points Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3169 Acce ...
- poj1329 Circle Through Three Points
地址:http://poj.org/problem?id=1329 题目: Circle Through Three Points Time Limit: 1000MS Memory Limit: ...
- poj 1329(已知三点求外接圆方程.)
Circle Through Three Points Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3766 Acce ...
- poj 1981 Circle and Points
Circle and Points Time Limit: 5000MS Memory Limit: 30000K Total Submissions: 8131 Accepted: 2899 ...
随机推荐
- spring boot starter开发
作为公司的技术保障部,一直承担着技术方向的把控,最近公司准备全面转入spring boot的开发.所以我们部门也一直在调研相关的技术知识点: 使用springboot开发应用已经有一段时间了,我们都沉 ...
- mysql定时任务(数据库管理工具and 纯命令行)
1.工具:Navicat 2.通过下列语句l爱查询event是否开启 打开Navicat命令列界面(点击工具可以看到或按F6) 输入下面命令 show variables like '%sche%'; ...
- JavaScript中如何让图形旋转不会相互影响
最近在联系JavaScript 二维绘图,经常会用到旋转,前几篇博文也提到过这类问题. 但是我忘记了JavaScript二维绘图中有关旋转最核心的两个方法:save()和restore() 在w3c上 ...
- QT5.2 Assistant-设置应用程序图标
在Qt助手(assistant.exe)搜索关键字"Setting the Application Icon"就可以看到在各种平台设置Qt程序图标的方法,包括QT支持的Win ...
- dubbo的一些特性理解一下
还有 启动检查.负载均衡.多协议支持 等 待总结
- c# SqlBulkCopy实现批量从数据集中把数据导入到数据库中
今天遇到了一个导入类第一次见 SqlBulkCopy 可以实现从一个数据集导入到数据库中的表中 本来想从数据集中一条条遍历insert到库中 有了这个后发现: 只在把表与数据集的列做一下对应关系,再走 ...
- 用Emacs进行Java开发
用Emacs进行Java开发 */--> code {color: #FF0000} pre.src {background-color: #002b36; color: #839496;} 用 ...
- spark复习总结02
1.spark执行原理图 spark程序启动后创建sparkContext作为程序的入口,sparkContext可以与不同类的集群资源管理器(Cluster Manager)进行通信,从而获得程序运 ...
- jquery.cookie.js实现cookie记住用户名和密码
记得导入 <script src="jquery.js" type="text/javascript"></script> <sc ...
- 【JDK1.8】Java HashMap实现细节
底层是用数组实现的 /** * The table, initialized on first use, and resized as * necessary. When allocated, len ...