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 ...
随机推荐
- 原生js实现拖拽效果
面向对象 + 原生js拖拽 拖拽div等盒子模型,都是日常操作没有什么问题,如果是拖拽图片的话,会有一点小坑要踩...... 那么我们看代码: var Move_fn = {}; (function( ...
- Linux环境下Eclipse对C++新特性的支持设置
Linux环境下Eclipse对C++新特性的支持设置 今天写一个简单的关于C11中的array容器的测试程序如下, #include <iostream> #include &l ...
- 在RedHat 7.2中安装boost库
在RedHat 7.2中安装boost库 环境,其它版本类似 Redhat7.2 64bit boost 1.64.0 步骤 去 boost官网 下载想要版本的.tar.gz,如下图 解压tar -v ...
- Redis 5.0.7 讲解,单机、集群模式搭建
Redis 5.0.7 讲解,单机.集群模式搭建 一.Redis 介绍 不管你是从事 Python.Java.Go.PHP.Ruby等等... Redis都应该是一个比较熟悉的中间件.而大部分经常写业 ...
- spss-数据清洗-处理重复数据
spss-数据清洗-处理重复数据 数据导入之后就需要对数据进行清洗.数据清洗主要是对多余重复的数据筛选清除,将缺失的数据补充完整,将错误的数据纠正或者删除.接下来操作如何将重复数据处理操作. 步骤一: ...
- 二级域名解析设置及Apache 子域名配置
域名管理解析项 如: cy.wanggangg.top 为wanggangg.top域名添加解析 主机记录设为 cy 记录值 为服务器ip地址 打开apache配置文件 新增如下:<Virtua ...
- Mysql 主从同步(转载)
第一步: 在master上创建用于同步的用户 GRANT FILE,REPLICATION SLAVE,REPLICATION CLIENT,SUPER ON *.* TObackup@'192.16 ...
- Sqlplus常用指令
一.ORACLE的启动和关闭1.在单机环境下2.在双机环境下二.Oracle数据库有哪几种启动方式1.startup nomount 非安装启动,这种方式启动下可执行:重建控制文件.重建数据库2.st ...
- spark复习总结01
1.MapReduce和spark的对比 MapReduce Spark 数据存储结构:磁盘hdfs文件系统的split 使用内存构建弹性分布式数据集RDD,对数据进行运算和cache 编程范式:Ma ...
- javascript中var同时声明多个变量时的原理是什么?
<script> function show(){ var a=b=c=d=5; } show(); alert(a);//弹a时报错(not defined),而b.c.d都能弹出5 & ...