zoj 1090 求三角形的外心(模板题)

来源:互联网 发布:vivo软件商店手机版 编辑:程序博客网 时间:2024/05/01 09:56
这个题目没得说,就直接套用三角形外心的模板就可以了。这个题目可以作为三角形外心的模板来用了。
#include<stdio.h>#include<math.h>#include<iostream>using namespace std;#define PI 3.141592653589793struct point{    double x;    double y;};struct Line{    point a;    point b;};point intersection(Line u,Line v){    point res=u.a;    double k=((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));    res.x+=(u.b.x-u.a.x)*k;    res.y+=(u.b.y-u.a.y)*k;    return res;}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 dis(point a,point b){    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}int main(){    point a,b,c;    while(scanf("%lf%lf%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y,&c.x,&c.y)!=EOF)    {        point ans=circumcenter(a,b,c);        printf("%.2lf\n",dis(ans,a)*PI*2);    }    return 0;}

原创粉丝点击