1. 程式人生 > 其它 >poj 2242(水題,注意分情況討論)

poj 2242(水題,注意分情況討論)

#include<iostream>
#define PI 3.141592653589793
#include<cmath>
using namespace std;
int main(){
    double x1,y1,x2,y2,x3,y3;
    double k1,b1,k2,b2,x,y,result;
    while(scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3)==6){
        if(x1==x2){
            y = (y1+y2)/2
; if(y1==y3){ x = (x1+x3)/2; } else{ k2 = -(x3-x1)/(y3-y1); b2 = (y1+y3)/2-k2*(x1+x3)/2; x = (y-b2)/k2; } } else{ if(y1==y2){ x = (x1+x2)/2;
if(x1==x3){ y = (y1+y3)/2; } else{ k2 = -(x3-x1)/(y3-y1); b2 = (y1+y3)/2-k2*(x1+x3)/2; y = k2*x+b2; } } else{ k1 = -(x2-x1)/(y2-y1); b1
= (y1+y2)/2-k1*(x1+x2)/2; if(x1==x3){ y = (y1+y3)/2; x = (y-b1)/k1; } else if(y1==y3){ x = (x1+x3)/2; y = k1*x+b1; } else{ k2 = -(x3-x1)/(y3-y1); b2 = (y1+y3)/2-k2*(x1+x3)/2; x = -(b2-b1)/(k2-k1); y = k1*x+b1; } } } result = PI*pow((x-x1)*(x-x1)+(y-y1)*(y-y1),0.5)*2; printf("%.2lf\n",result); } return 0; }