Sort by

recency

|

9 Discussions

|

  • + 0 comments

    I've got a question: Suppose Jim is at (0,0), the mirror is at (0,2) and the wall goes from (0,1) to (1,1); now, can Jim cast the beam or not? It depends: If the wall is an open line segment (doesn't include the endpoints) the answer is YES, while if it's close, the answer is NO.

    Do we know which case we're dealing with?

  • + 0 comments

    I suggest using vectors. Solve vector form of solution for pi + siqi
    where pi are the position vectors and qi the translation ones
    for the scalars s.
    For intercept, system must be solvable and both scalars are >= 0 and <= 1.
    otherwise there is none.

  • + 0 comments

    include

    using namespace std;

    int main() { int t; cin>>t; double x1,y1,x2,y2,xm,ym,x0,y0; for(int i=0;i

        for(int i=0;i<6;i++)
        {
            cin>>arr[i];
    
        }
    
       x1=arr[0];y1=arr[1];x2=arr[2];y2=arr[3];xm=arr[4];ym=arr[5];
       x0=0;y0=0;
    
       double t=(x0-x1)*(y2-y1)-(x2-x1)*(y0-y1);
       double p=(xm-x1)*(y2-y1)-(x2-x1)*(ym-y1);
    
       if(t<0 && p<0)
       {
           cout<<"YES"<<endl;
       }
       else if(t>0 && p>0)
       {
           cout<<"YES"<<endl;
       }
       else if(t==0 && p>0)
       {
           cout<<"YES"<<endl;
    
       }
       else if(t==0 && p<0)
       {
           cout<<"YES"<<endl;
       }
    
       else if(t==0 && p==0)
       {
           if(xm==0 && abs(ym)<abs(y1) && abs(ym)<abs(y2))
           {
               cout<<"YES"<<endl;
           }
           else if(ym==0 && abs(xm)<abs(x1) && abs(xm)<abs(x2))
           {
               cout<<"YES"<<endl;
           }
           else if  (xm==0 && ym==0)
           {
                cout<<"YES"<<endl;
           }
           else if (ym/xm==(y2-y1)/(x2-x1)){
    
                if(xm<x1 &&xm<x2)
                cout<<"YES"<<endl;
           else
            cout<<"NO"<<endl;
    
           }
       }
       else
       {
           if(xm==0)
           {
               if((x1>=0 && x2<=0)||(x1<=0 && x2>=0))cout<<"NO"<<endl;
               else cout<<"YES"<<endl;
           }
           else if(ym==0)
           {
               if((y1>=0 && y2<=0)||(y1<=0 && y2>=0))cout<<"NO"<<endl;
               else cout<<"YES"<<endl;
    
           }
           else
           {
               double t=(y2-y1)-(x2-x1)*ym/xm;
               double p=x1*(y2-y1)-y1*(x2-x1);
               double x=p/t;
               if((x1>=x && x2<=x)||(x1<=x && x2>=x))cout<<"NO"<<endl;
               else cout<<"YES"<<endl;
    
    
           }
       }
    
    
    
    
    }
    
    
    }
    
  • + 1 comment

    The solution method proposed by the editorial is non-obvious and possibly more complicated than it needs to be. A more intuitive and straightforward method (to this former vector calculus teacher) is to use parametric equations to describe the beampath and the wall. If Ri is the vector = , then problem can be rewritten " Does there exist an s and t (both between 0 and 1) so that s*R2 + (1-s)*R1 = t*Rm. From there it is straightforard linear algebra. The only special case that needs any particular care is the case where the lines are parallel, so the equations are indeterminate.

    • + 0 comments

      Yeah, this is equivalent to finding whether two line segments intersect (as is said at the beginning of the editorial), which is a standard problem in computational geometry.

      I actually did the problem in a even more non-obvious way. I put the source at the origin and establish a non-orthogonal coordinate system with the two endpoints of the wall lying on its x and y axes (which need not be perpendicular). In the non-orthogonal system, a point (x,y) is blocked by the wall iff x>=0 and y>=0 and x+y>=1 at the same time. It is then the computer's job to do the coordinate transform. I've got to treat as a special case the situation when the x and y axes coincide.

  • + 1 comment

    Can someone please check my code submission? I am getting wrong answer for all except the sample test case although I feel I am close to the answer.

    • + 2 comments

      you can download the failing testcase and test the code in your local machine or paste it in the custom testcase window to debug your code. a video explaining the same is given here

      • + 0 comments

        Video link seems to not be working for me.

      • + 0 comments

        I just got it, small fix to a test situation in my code. Due to the fact that the video link does not seem to work, or does not work for me, if anyone needs help these are a couple of the refferences I used to solve the problem:

        http://www.uiowa.edu/~examserv/mathmatters/tutorial_quiz/geometry/findingptsofintersection.html

        http://www.mathopenref.com/coordintersection.html