UVA 438 (The Circumference of the Circle) Solution

Hints:
Suppose that the coordinates of the three points are  (a1,a2), (b1,b2), and (c1,c2).

Compute the following three values.  If the value of   is 0, they lie on a line so there's no circle to have a center.

            

                           

                           

Then the center has coordinates  (x,y)  where

                      

                      


Solve in C:


#include<stdio.h>
#include<math.h>
int main(){

double a1,a2,b1,b2,c1,c2,x,y,pi=3.141592653589793,d,u,v,r,c;
while(scanf("%lf%lf%lf%lf%lf%lf",&a1,&a2,&b1,&b2,&c1,&c2)!=EOF)
{
    d=(a1-b1)*(b2-c2)-(b1-c1)*(a2-b2);
  u=(((a1*a1)-(b1*b1))+((a2*a2)-(b2*b2)))/2.0;
  v=((b1*b1)-(c1*c1)+(b2*b2)-(c2*c2))/2.0;

  x=((u*(b2-c2))-(v*(a2-b2)))/d;

 y=((v*(a1-b1))-(u*(b1-c1)))/d;

    r=sqrt(((x-a1)*(x-a1)+(y-a2)*(y-a2)));
    c=2*pi*r;

    printf("%.2lf\n",c);
}


}



No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

Powered by Blogger.