1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
#include <stdio.h> #include <iostream> #include <math.h> using namespace std; #define eps 1e-6 #define MX 1000000000 #define ll long long struct POINT{int x,y;}; long long gcd(ll a,ll b) { if(a%b==0) return b; else return gcd(b,a%b); } POINT pp[4]; bool find_perp_distance(POINT u,POINT v,POINT s,ll &B,ll &C,double &val) { //form equation of st line uv (ax+by+c=0) double a,b,c,r; a = u.y-v.y;//y1-y2 b = v.x-u.x; c = -(a*u.x+b*u.y); //distance from a point d = (a*x+b*y+c)/sqrt(a*a+b*b) r = fabs(a*s.x+b*s.y+c)/sqrt(a*a+b*b); //here if v can be considered as the edge of the square or diameter of the inscribed circle //so the area of the circle = d*d/4 * PI //cout<<r<<"\n"; if(r<eps) return 0; if(r < val) { B=a*s.x+b*s.y+c; B=B*B; C=a*a+b*b; val=r; } return 1; } int main() { int a,ans,b; double compare; ll B,C,g; bool f1,f2; while(cin>>a) { cin>>b; pp[0].x=a; pp[0].y=b; for(int i=1;i<=3;i++) { cin>>a>>b; pp[i].x=a;pp[i].y=b; } ans=0; for(int i=0;i<=3;i++) { ans+=(pp[i].x+pp[i].y); } if(ans==0) break; compare = MX; //find perpendicular distance from first point to the st line of 2nd and 3rd point f1 = find_perp_distance(pp[0],pp[1],pp[2],B,C,compare); f2 = find_perp_distance(pp[1],pp[2],pp[3],B,C,compare); if(f1*f2==0) { cout<<-1<<"\n"; continue; } C*=4; g = gcd(B,C); B/=g; C/=g; cout<<"("<<B<<"/"<<C<<")*pi\n"; } return 0; } |