Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std ;
- #define M 999999999999999999
- #define pii pair<int , int >
- #define mp make_pair
- #define pf printf
- #define sf scanf
- #define sf1(a ) scanf("%d",&a)
- #define pb push_back
- #define sf2(a, b) scanf("%d%d",&a ,&b)
- #define rep(i,n ) for(i = 0 ; i< n ;i++ )
- typedef long long LL ;
- LL num ;
- struct _line{
- double a , b ,c , m , mid_x, mid_y ;
- };
- struct _point
- {
- double x , y;
- };
- vector<_line> line ;
- vector<_point> point ;
- double p_1 , p_2;
- void call(_point p1 , _point p2); // makes line eqn from 2 points
- void make_line(_line p1 );
- int i_sec(_line p1 , _line p2);
- void print(double rad){
- double c ;
- c = p_1*p_1 +p_2*p_2 - rad*rad ;
- /*if(p_1 == 0 && p_2 == 0){
- pf("x^2 + y^2 = %.3lf^2\n",rad );
- if(c < 0)
- pf("x^2 + y^2 - %.3lf = 0\n",p_1*2 , p_2*2,-c );
- else
- pf("x^2 + y^2 + %.3lf = 0\n",p_1*2 , p_2*2,c );
- return ;
- }
- else if(p_1 == 0){
- pf("x^2 + (y - %.3lf)^2 = %.3lf^2\n", p_2 ,rad );
- if(c < 0)
- pf("x^2 + y^2 - %.3lfy - %.3lf = 0\n" , p_2*2,-c );
- else
- pf("x^2 + y^2 - %.3lfy + %.3lf = 0\n", p_2*2,c );
- }
- else if(p_2 == 0)
- {
- pf("(x - %.3lf)^2 + y^2 = %.3lf^2\n",p_1 ,rad );
- if(c < 0)
- pf("x^2 + y^2 - %.3lfx - %.3lf = 0\n",p_1*2 ,-c );
- else
- pf("x^2 + y^2 - %.3lfx + %.3lf = 0\n",p_1*2 ,c );
- }*/
- if(p_1 > 0 && p_2 > 0){
- pf("(x - %.3lf)^2 + (y - %.3lf)^2 = %.3lf^2\n",p_1 , p_2 ,rad );
- if(c < 0)
- pf("x^2 + y^2 - %.3lfx - %.3lfy - %.3lf = 0\n",p_1*2 , p_2*2,-c );
- else
- pf("x^2 + y^2 - %.3lfx - %.3lfy + %.3lf = 0\n",p_1*2 , p_2*2,c );
- }
- else if(p_1 < 0 && p_2< 0){
- pf("(x + %.3lf)^2 + (y + %.3lf)^2 = %.3lf^2\n",-p_1 , -p_2 ,rad );
- if(c >= 0)
- pf("x^2 + y^2 + %.3lfx + %.3lfy + %.3lf = 0\n",-p_1*2 , -p_2*2,c );
- else
- pf("x^2 + y^2 + %.3lfx + %.3lfy - %.3lf = 0\n",-p_1*2 , -p_2*2,-c );
- }
- else if(p_1 < 0 && p_2 > 0){
- pf("(x + %.3lf)^2 + (y - %.3lf)^2 = %.3lf^2\n",-p_1 , p_2 ,rad );
- if(c >= 0)
- pf("x^2 + y^2 + %.3lfx - %.3lfy + %.3lf = 0\n",-p_1*2 , p_2*2,c );
- else
- pf("x^2 + y^2 + %.3lfx - %.3lfy - %.3lf = 0\n",-p_1*2 , p_2*2,-c);
- }
- else if(p_1 >0 && p_2 <0){
- pf("(x - %.3lf)^2 + (y + %.3lf)^2 = %.3lf^2\n",p_1 , -p_2 ,rad );
- if(c >= 0)
- pf("x^2 + y^2 - %.3lfx + %.3lfy + %.3lf = 0\n",p_1*2 , -p_2*2,c );
- else
- pf("x^2 + y^2 - %.3lfx + %.3lfy - %.3lf = 0\n",p_1*2 , -p_2*2,-c );
- }
- return ;
- }
- int main(){
- freopen("in.txt","r",stdin );
- freopen("out.txt","w",stdout );
- double x1 , y1 ;
- int i , j ,k ;
- while( scanf("%lf %lf",&x1 , &y1)==2 ){
- point.clear();
- line.clear();
- _point pvar;
- pvar.x = x1;
- pvar.y = y1 ;
- point.push_back(pvar);
- for(i = 2;i<= 3 ; i++){
- scanf("%lf %lf",&x1 , &y1);
- pvar.x = x1;
- pvar.y = y1 ;
- point.push_back(pvar);
- }
- call(point[0] , point[1]);
- call(point[1] , point[2]);
- call(point[2] , point[0]);
- /* for(i = 0 ;i< 3 ;i++)
- {
- _line v ;
- v = line[i];
- // pf("line %d : %lf %lf %lf %lf %lf %lf\n",i ,v.a , v.b , v.c , v.m ,v.mid_x , v.mid_y);
- }
- */
- make_line(line[0] );
- make_line(line[1] );
- make_line(line[2] );
- //pf("printing derived line\n");
- // for(i = 3 ;i< 6 ;i++)
- //{
- // _line v ;
- // v = line[i];
- // pf("line %d : %lf %lf %lf %lf %lf %lf\n",i ,v.a , v.b , v.c , v.m ,v.mid_x , v.mid_y);
- // }
- i_sec(line[3] ,line[4]);
- // pf("intersecting %lf %lf\n",p_1 , p_2 );
- double rad ;
- rad = sqrt((p_1 - point[0].x)*(p_1 - point[0].x) + (p_2 - point[0].y)*(p_2 - point[0].y));
- // pf("intersecting %lf %lf %lf\n",p_1 , p_2, rad );
- print(rad);
- pf("\n");
- }
- return 0 ;
- }
- void call(_point p1, _point p2 ){
- double x1 ,y1 ,x2, y2 ;
- x1 = p1.x;
- x2 = p2.x;
- y1 = p1.y;
- y2 = p2.y;
- _line var ;
- var.mid_x =( x1 + x2)/2 ;
- var.mid_y = (y1 + y2)/2 ;
- if(y1 == y2){
- var.a = 0;
- var.b = 1;
- var.c = -y1;
- var.m = 0;
- line.push_back(var);
- return ;
- }
- else if(x1 == x2 ){
- var.a = 1;
- var.b = 0;
- var.c = -x1;
- var.m = 0;
- line.push_back(var);
- return ;
- }
- else {
- double ret ;
- ret =(double) (y2 - y1)/(x2 - x1);
- var.a = ret ;
- var.b = -1;
- var.c = -ret*x1 +y1;
- var.m = ret ;
- line.push_back(var);
- return ;
- }
- }
- void make_line(_line p1){
- _line var ;
- double slope , x1, y1 ;
- slope = var.m = -1/p1.m;
- if(p1.m == 0) slope = 0;
- x1 = p1.mid_x;
- y1 = p1.mid_y;
- var.a = -slope ;
- var.b = 1;
- var.c = -y1 + slope*x1;
- line.push_back(var);
- return ;
- }
- int i_sec(_line p1 , _line p2){
- double ret , ret1, ret2 , x1 ,y1 ,x2 ,y2;
- double px1, px2 , py1 ,py2;
- double a1, b1 ,c1 , a2 ,b2 ,c2 ;
- a1 = p1.a ;
- b1 = p1.b ;
- c1 = p1.c ;
- a2 = p2.a ;
- b2 = p2.b ;
- c2 = p2.c ;
- double hold ,k1 ,k2;
- hold = a1*b2 - a2*b1 ;
- if(hold == 0 ) cout << "trrrrr\n";
- k1 = (double) (b1*c2 - b2*c1)/hold ;
- k2 = (double)(c1*a2 - c2*a1)/hold ;
- p_1 = k1 ;
- p_2 = k2 ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement