poj 2242(水題,數學題)
阿新 • • 發佈:2021-07-31
#include<iostream> #include<cstdio> using namespace std; #define PI 3.141592653589793 #include<cmath> int main(){ double x1,y1,x2,y2,x3,y3; double k1,k2,ansx,ansy,ans; while(scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3)==6){ double a = x1-x2;double b = y1-y2; double c = x1-x3; double d = y1-y3; if(a==0){//直線1平行於y軸,中垂線1平行於x軸且過中點 k1 = 0; ansy = (y1+y2)/2; if(d==0)//直線2平行於x軸,中垂線2平行於y軸且過中點 ansx = (x1+x3)/2; else{ k2 = -(x3-x1)/(y3-y1); // ansx = ((y2-y3)-k2*(x1+x3))/(2*k2);ansx = (x1+x3)/2+(y2-y3)/2/k2; } } else if(b==0){//直線1平行於x軸,中垂線平行於y軸且過中點 ansx = (x1+x2)/2; if(c==0)//直線2平行於y軸,中垂線2平行於x軸且過中點 ansy = (y1+y3)/2; else{ k2 = -(x3-x1)/(y3-y1); ansy = (y1+y3)/2+k2*(x2-x3)/2; } } else{ k1 = -(x2-x1)/(y2-y1); if(c==0){//直線2平行於y軸,中垂線2平行於x軸且過中點 ansy = (y1+y3)/2; ansx = (x1+x2)/2+(y3-y2)/2/k1; }else if(d==0){ ansx = (x1+x3)/2; ansy = (y1+y2)/2+k1*(x3-x2)/2; } else{ k2 = -(x3-x1)/(y3-y1); ansx = (k1*(x1+x2)/2-k2*(x1+x3)/2-(y2-y3)/2)/(k1-k2); ansy = k1*(ansx-(x1+x2)/2)+(y1+y2)/2; } } ans = 2*PI*(sqrt((x1-ansx)*(x1-ansx)+(y1-ansy)*(y1-ansy))); printf("%.2lf\n",ans); } return 0; }