栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

poj 1329 Circle Through Three...

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

poj 1329 Circle Through Three...

#include <iostream>#include <math.h>#include <stdio.h>#define pi acos(-1.0)struct point{ double x, y; };struct line{ point a, b; };double xmult(point p1, point p2, point p0){return (p1.x - p0.x)*(p2.y - p0.y) - (p2.x - p0.x)*(p1.y - p0.y);}char sign(double a){return a > 0 ? '-' : '+';}char sign2(double a){return a > 0 ? '+' : '-';}double distance(point p1, point p2){return sqrt((p1.x - p2.x)*(p1.x - p2.x) + (p1.y - p2.y)*(p1.y - p2.y));}point intersection(line u, line v){point ret = u.a;double t = ((u.a.x - v.a.x)*(v.a.y - v.b.y) - (u.a.y - v.a.y)*(v.a.x - v.b.x))/ ((u.a.x - u.b.x)*(v.a.y - v.b.y) - (u.a.y - u.b.y)*(v.a.x - v.b.x));ret.x += (u.b.x - u.a.x)*t;ret.y += (u.b.y - u.a.y)*t;return ret;}//外心point circumcenter(point a, point b, point c){line u, v;u.a.x = (a.x + b.x) / 2;u.a.y = (a.y + b.y) / 2;u.b.x = u.a.x - a.y + b.y;u.b.y = u.a.y + a.x - b.x;v.a.x = (a.x + c.x) / 2;v.a.y = (a.y + c.y) / 2;v.b.x = v.a.x - a.y + c.y;v.b.y = v.a.y + a.x - c.x;return intersection(u, v);}double area_***(point p1, point p2, point p3){return fabs(xmult(p1, p2, p3)) / 2;}int main(){point a, b, c;while (std::cin >> a.x >> a.y >> b.x >> b.y >> c.x >> c.y){point center = circumcenter(a, b, c);double p = distance(a, b) * distance(a, c) * distance(b, c);double r = 1.0 * p / (4.0*area_***(a, b, c));printf("(x %c %.3f)^2 + (y %c %.3f)^2 = %.3f^2n", sign(center.x), fabs(center.x), sign(center.y), fabs(center.y),r);printf("x^2 + y^2 %c %.3fx %c %.3fy %c %.3f = 0n", sign(center.x), 2 * fabs(center.x), sign(center.y), 2 * fabs(center.y), sign2(center.x * center.x + center.y * center.y - r * r), fabs(center.x * center.x + center.y * center.y - r * r));puts("");}}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/377237.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号