453 PE

All about problems in Volume IV. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

453 PE

Postby jurajz » Mon Feb 26, 2007 12:31 am

Many threads to this problem are about Wrong Answer. My first submit was WA too, but next 4 submissions I had PE. I don't understand, why :(

I think, that messages ("NO INTERSECTION" or "THE CIRCLES ARE THE SAME") and coordinates of the points (with parenthesis) I print correct, without any blanks. I think about extra lines in the end of input. I avoid to write "-0.000", I write "0.000". But still PE. Blank lines shouldn't be here...

Have someone idea, where may be the reason of PE? Many solution have PE in this problem. {198 AC/ 145 PE in this time}

Thanks in advance!

Please sorry for my bad english.
jurajz
Learning poster
 
Posts: 66
Joined: Sat Sep 02, 2006 7:30 pm
Location: Slovakia

Postby Jan » Mon Feb 26, 2007 1:57 pm

I got PE several times, too. Then I changed the 'eps' value and got accepted.
Ami ekhono shopno dekhi...
HomePage
Jan
Guru
 
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh

Postby jurajz » Mon Feb 26, 2007 9:17 pm

Many thanks, Jan. After 6 PE I got Accepted. You are right, PE is caused by EPS value. For 10^( -12 ) or 10^( -8 ) it is PE. For 10^( -4 ) it is AC.
jurajz
Learning poster
 
Posts: 66
Joined: Sat Sep 02, 2006 7:30 pm
Location: Slovakia

Postby erdos » Thu May 03, 2007 10:00 pm

I've tried with Epsilon = 1e-4 and 1e-8 and got PE in both cases.
What might be wrong?
The PE ratio is also quite high.
This problem has a special corrector (probably because of the accuracies?)
erdos
New poster
 
Posts: 32
Joined: Sat Jul 06, 2002 9:38 pm
Location: Lisbon

453 WA

Postby likhan » Sat Jun 09, 2007 12:55 pm

Everybody is talking about getting PE, but man I cannot remove WA talk about PE later. Anyways looked for Adrian's inputs, but they are not any more available neither from Stefen site nor Adrians. Somebody please come to rescue, I'm going crazy already tried arnd 20 submissions with different combinations. Heeeeeeeeeelllllllllpppppppppp.

Code: Select all
#include <stdio.h>
#include <math.h>

#define EPS 1e-4
#define EQUAL(a,b) (fabs((a)-(b))<EPS)
#define ROUND(a) ((long)(((a)+5e4)*1000))
#define SQR(a) ((a)*(a))
#define ZERO(a) (fabs(a)<EPS)

void main()
{
   double x1, y1, r1, x2, y2, r2, D, A, ix1, iy1, ix2, iy2;

   //freopen("453.in", "r+", stdin);

   //printf("%lf", EPS);

   while ( scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &r1, &x2, &y2, &r2) == 6 )
   {
      D = SQR(x1 - x2) + SQR(y1 - y2);
      D = sqrt(D);
      A = (D + r1 + r2) * (D + r1 - r2) * (D - r1 + r2) * (-D + r1 + r2);

      if ( EQUAL(x1, x2) && EQUAL(y1, y2) && EQUAL(r1, r2) )
      {
         puts("THE CIRCLES ARE THE SAME");
      }
      else if (D < fabs(r1 - r2) || D > (r1 + r2) )
      //else if ((r1 + r2) < D )
      {
         puts("NO INTERSECTION");
      }
      else
      {
         A = (sqrt(A) / 4.0);
         ix1 = ix2 = ((x1 + x2) / 2) - (((x1 - x2) * (SQR(r1)-SQR(r2))) / (2 * SQR(D)));
         ix1 = ix1 + ((2 * (y1 - y2) * A) / SQR(D));
         ix2 = ix2 - ((2 * (y1 - y2) * A) / SQR(D));

         iy1 = iy2 = ((y1 + y2) / 2) - (((y1 - y2) * (SQR(r1)-SQR(r2))) / (2 * SQR(D)));
         iy1 = iy1 - ((2 * (x1 - x2) * A) / SQR(D));
         iy2 = iy2 + ((2 * (x1 - x2) * A) / SQR(D));

         ix1 = (ZERO(ix1) ? 0 : ix1);
         iy1 = (ZERO(iy1) ? 0 : iy1);
         ix2 = (ZERO(ix2) ? 0 : ix2);
         iy2 = (ZERO(iy2) ? 0 : iy2);

         //if ( ROUND(ix1) == ROUND(ix2) && ROUND(iy1) == ROUND(iy2) )
         if ( EQUAL(ix1, ix2) && EQUAL(iy1, iy2) )
         {
            printf("(%.3lf,%.3lf)\n", ix1, iy1);
         }
         else
         {
            if ( (ix1 < ix2) || (EQUAL(ix1, ix2) && (iy1 < iy2)) )
               printf("(%.3lf,%.3lf)(%.3lf,%.3lf)\n", ix1, iy1, ix2, iy2);
            else
               printf("(%.3lf,%.3lf)(%.3lf,%.3lf)\n", ix2, iy2, ix1, iy1);
         }
      }
   }
}
likhan
New poster
 
Posts: 21
Joined: Tue Nov 06, 2001 2:00 am
Location: Kyliptix Solutions

Postby kn » Wed Jun 20, 2007 9:55 pm

Really tough problem...
My code passed the test case provided by the other post...yet, WA

Round-off problem is difficult to tackle... for this online judge.
I think dealing with the round-off error "correctly" requires some "luck".

BTW, why I can't search the posts of this problem after I entered "453"?

Code: Select all
#include <iostream>
#include <cstdio>
#include <math.h>
#define EPSILON 1e-4

using namespace std;

double xc1, xc2, yc1, yc2;
double r1, r2;

inline bool EQUAL(double X, double Y){
   return fabs(X-Y)<EPSILON;
}

inline double zz(double X){
   if(fabs(X)<EPSILON)   return 0.000;
   else   return X;
}

void printPair(double X, double Y);

int main(){
   while(scanf("%lf", &xc1)!=EOF){
      scanf("%lf %lf", &yc1, &r1);
      scanf("%lf %lf %lf", &xc2, &yc2, &r2);
   
      if(EQUAL(xc1,xc2) && EQUAL(yc1,yc2) && EQUAL(r1,r2)){
         if(EQUAL(r1,0.000)&&EQUAL(r2,0.000))
            printf("(%.3lf,%.3lf)\n",xc1,yc1);
         else
            printf("THE CIRCLES ARE THE SAME\n");
         continue;
      }

      double dx = xc1-xc2;
      double dy = yc1-yc2;
      double sqD = dx*dx+dy*dy;
      double sumR = r1+r2;
      double sqSumR = sumR*sumR;
      double diffR = r1-r2;
      double sqDiffR = diffR*diffR;
   
      if(EQUAL(sqD,sqSumR)){
         // Touch externally
         // Exactly 1 intersecting pt
         double ratio = r2/sumR;
         printPair(xc2+dx*ratio, yc2+dy*ratio);
         printf("\n");
      }else{
         // Find Equation of Chord...
         double d1=-2*xc1, e1=-2*yc1, f1=xc1*xc1+yc1*yc1-r1*r1;
         double d2=-2*xc2, e2=-2*yc2, f2=xc2*xc2+yc2*yc2-r2*r2;
         double A=d1-d2, B=e1-e2, C=f1-f2;
         double xFinal, yFinal;
         
         // Touches internally
         // Exactly 1 intersectin pt
         if(EQUAL(sqD,sqDiffR)){
            if(EQUAL(B,0.000)){
               xFinal = -C/A;
               yFinal = yc1;
            }else{
               double AoverB = A/B, CoverB = C/B;
               double a=1+AoverB*AoverB;
               double b=-2*xc1+2*AoverB*(yc1+CoverB);
               xFinal = -b/2/a;
               yFinal = -AoverB*xFinal - CoverB;
            }
            printPair(xFinal, yFinal);
            printf("\n");
         }else if(sqD > sqSumR || sqD < sqDiffR){
            // No intersection
            printf("NO INTERSECTION\n");
         }else{
            // Distinct intersections
            if(EQUAL(B,0.000)){
               printf("EQUAL B, DISTINCT\n");
               
               xFinal = -C/A;
               double temp=xFinal-xc1;
               double c=r1*r1-temp*temp;
               double rDelta=sqrt(c);
               printPair(xFinal, yc1-rDelta);
               printPair(xFinal, yc1+rDelta);
            //   printf("(%.3lf,%.3lf)\n", zz(xFinal), yc1+rDelta);
            }else{
               double AoverB = A/B, CoverB = C/B;
               double a=1+AoverB*AoverB;
               double b=-2*xc1+2*AoverB*(yc1+CoverB);
               double temp=CoverB+yc1;      temp*=temp;
               double c=xc1*xc1+temp-r1*r1;
               double DELTA = b*b-4*a*c;
               double rDelta = sqrt(DELTA);
               xFinal = (-b-rDelta)/2/a;
               yFinal = -AoverB*xFinal - CoverB;
               printPair(xFinal, yFinal);
               
               xFinal = (-b+rDelta)/2/a;
               yFinal = -AoverB*xFinal - CoverB;
               printPair(xFinal, yFinal);
            }
            printf("\n");
         }
      }
   }
   return 0;
}

void printPair(double X, double Y){
   printf("(%.3lf,%.3lf)", zz(X), zz(Y));
}
kn
New poster
 
Posts: 28
Joined: Fri Apr 13, 2007 8:53 am

Re: 453 PE

Postby h.hesham » Sun Aug 05, 2012 7:00 am

Code: Select all
if(EQUAL(xc1,xc2) && EQUAL(yc1,yc2) && EQUAL(r1,r2))


your problem is here, an infinite number of points does not mean that they MUST be the same (although the output says so)
h.hesham
New poster
 
Posts: 1
Joined: Sun Aug 05, 2012 6:56 am


Return to Volume IV

Who is online

Users browsing this forum: No registered users and 1 guest