POJ 1329 三角外接圆
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 3169 | Accepted: 1342 |
Description
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
Output
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
给定三个点,求三角形的外接圆,题目非常easy,练一下计算几何的模板代码。输出非常恶心。
代码:
/* ***********************************************
Author :rabbit
Created Time :2014/4/19 23:46:03
File Name :8.cpp
************************************************ */
#pragma comment(linker, "/STACK:102400000,102400000")
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <string>
#include <time.h>
#include <math.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
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)<eps)return 0;
return 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;
}
POJ 1329 三角外接圆的更多相关文章
- POJ 1329 Circle Through Three Points(三角形外接圆)
题目链接:http://poj.org/problem?id=1329 #include<cstdio> #include<cmath> #include<algorit ...
- 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 ...
- poj 1329(已知三点求外接圆方程.)
Circle Through Three Points Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3766 Acce ...
- 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
模板题,注意一下输出就可以. #include <iostream> #include <cstdio> #include <cmath> #include < ...
- [转] POJ计算几何
转自:http://blog.csdn.net/tyger/article/details/4480029 计算几何题的特点与做题要领:1.大部分不会很难,少部分题目思路很巧妙2.做计算几何题目,模板 ...
- ACM计算几何题目推荐
//第一期 计算几何题的特点与做题要领: 1.大部分不会很难,少部分题目思路很巧妙 2.做计算几何题目,模板很重要,模板必须高度可靠. 3.要注意代码的组织,因为计算几何的题目很容易上两百行代码,里面 ...
随机推荐
- [原]Unity3D深入浅出 - 雾效(Fog)
在Unity中开启雾效的方式:依次选中菜单栏中的 Edit - Render Settings 项,勾选Fog 选框即可开启雾效.雾效的参数如下: Fog Color:雾的颜色. Fog Mode:雾 ...
- HNOI2008玩具装箱 (斜率优化)
总算A了,心情好激动…… 如果会了一类斜率优化,基本上这类题就成了套模版了…… 只是k函数不同 var n,l,x,tail,head,m:int64; i,j:longint; dp,q,s:..] ...
- [HDU 1695] GCD
GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- 理解java reference
Java世界泰山北斗级大作<Thinking In Java>切入Java就提出“Everything is Object”.在Java这个充满Object的世界中,reference是一 ...
- POJ 1815 Friendship ★(字典序最小点割集)
[题意]给出一个无向图,和图中的两个点s,t.求至少去掉几个点后才能使得s和t不连通,输出这样的点集并使其字典序最大. 不错的题,有助于更好的理解最小割和求解最小割的方法~ [思路] 问题模型很简单, ...
- apache开源项目--Apache Drill
为了帮助企业用户寻找更为有效.加快Hadoop数据查询的方法,Apache 软件基金会发起了一项名为“Drill”的开源项目.Apache Drill 实现了 Google's Dremel. Apa ...
- undo日志
InnoDB’s Undo 前言 Undo log是InnoDB MVCC事务特性的重要组成部分.当我们对记录做了变更操作时就会产生undo记录,Undo记录默认被记录到系统表空间(ibdata)中, ...
- POJ 3107-Godfather(树形dp)
题意: 有n个节点的树,删除一个点,得到的最大联通分支最小,求这样点的集合 分析: dp[i]表示删除i所得最大联通分支,遍历一遍节点即可,该题用vector会超时 #include <map& ...
- 解决session失效之后登陆后重新返回之前的页面
在全局拦截器设置保存之前的url存入session中 登陆之后的地址再重session中存 request只用作一次请求 如果页面跳转几次的话原来的url就不存在了建议存在session @Overr ...
- 深入浅出JavaScript函数 v 0.5
本文的观点是建立在<JavaScript权威指南 6th Ed> <JavaScript高级编程 3th Ed> <JavaScript精粹 2th Ed>之上, ...