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.

  • + 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.