ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1348. Goat in the Garden 2

I am having wrong answer in test 26...May I know what is test 26 or what mistake I made?
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <cstdio>

using namespace std;

double dist(int x1, int y1, int x2, int y2)
{
     return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}



int main()
{
     double mlen,rlen,dmin,dmax,dtemp,dab_bc_ca[3];
     //mlen is the perpendicular distance from C to AB
     //rlen is Rope Length
     //dab_bc_ca is length of AB, BC and CA
     int x1,y1,x2,y2,cx,cy;
     cin>>x1>>y1>>x2>>y2>>cx>>cy>>rlen;

     if (x1==x2 & y1==y2) //when A and B are same points
     {
          dtemp=dist(x1,y1,cx,cy);
          if (dtemp>rlen)
          dmin=dist(x1,y1,cx,cy)-rlen;
          else dmin=0.00;
          printf("%.2f\n%.2f",dmin,dmin);

     }
     else if (x1!=x2 or y1!=y2)
     {
     mlen=cx*(y1-y2)+cy*(x2-x1)+y1*(x1-x2)-x1*(y1-y2);
     mlen=abs(mlen)/dist(x1,y1,x2,y2);

     if (mlen==0)//Check the position of C, inside AB or Not?
     {
          if (dist(x1,y1,cx,cy)+dist(x2,y2,cx,cy)==dist(x1,y1,x2,y2)) printf("0.00\n");
          else {
                    dtemp=min(dist(cx,cy,x1,y1),dist(cx,cy,x2,y2));
                    if (rlen>=dtemp) printf("0.00\n");
                    else printf("%.2f\n",dtemp-rlen);
               }
          dmax=max(dist(x1,y1,cx,cy),dist(x2,y2,cx,cy));
          if (rlen>=dmax) cout<<"0.00";
          else printf("%.2f",dmax-rlen);
     }
     else //C is outside of AB
     {
          dab_bc_ca[0]=dist(x1,y1,x2,y2); //AB
          dab_bc_ca[1]=dist(x2,y2,cx,cy); //BC
          dab_bc_ca[2]=dist(x1,y1,cx,cy); //CA
          sort(dab_bc_ca+0,dab_bc_ca+3);
          if (dab_bc_ca[2]*dab_bc_ca[2]>dab_bc_ca[1]*dab_bc_ca[1]+dab_bc_ca[0]*dab_bc_ca[0])
          {
               //For Obtuse Angle Triangle
               dab_bc_ca[2]=dist(x1,y1,cx,cy); //CA
               dab_bc_ca[1]=dist(x2,y2,cx,cy); //CB
               dtemp=max(dab_bc_ca[2],dab_bc_ca[1]);
               //Rope length is biggest
               if (rlen>=dtemp) printf("0.00\n0.00");
               else
               {
                    dtemp=min(dist(x1,y1,cx,cy),dist(x2,y2,cx,cy));
                    if (rlen>=dtemp) printf("0.00\n");
                    else printf("%.2f\n",dtemp-rlen);
                    dtemp=max(dist(x1,y1,cx,cy),dist(x2,y2,cx,cy));
                    printf("%.2f",dtemp-rlen);
               }

          }

          else
          {
               //for Acute angle Triangle
               if (rlen>=mlen) cout<<"0.00\n"<<endl;
               else printf("%.2f\n",mlen-rlen);
               dtemp=max(dist(x1,y1,cx,cy),dist(x2,y2,cx,cy));
               if (rlen>=dtemp) cout<<"0.00";
               else printf("%.2f",dtemp-rlen);
          }
     }
     }
     return 0;
}