We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
//distance from p1 to p2 to the power of 2inlinelongdistance_p2(longp1x,longp1y,longp2x,longp2y){returnstd::abs((p1x-p2x)*(p1x-p2x)+(p1y-p2y)*(p1y-p2y));}//distance from s to the nearest point on p1 - p2 to the power of 2floatdistance_to_line_p2(longsx,longsy,longp1x,longp1y,longp2x,longp2y){longe1=distance_p2(sx,sy,p1x,p1y),//s - p1e2=distance_p2(sx,sy,p2x,p2y),//s - p2e3=distance_p2(p1x,p1y,p2x,p2y);//p1 - p2if(e3+e1<=e2||e3+e2<=e1){//if s-p1-p2 or 2-p2-p1 is an obtuse (or right) angle, the nearest point is one of the two verticesreturnstd::min(e1,e2);}//else return the length of altitude (from s) to the power of twolonglongnum=(longlong)e1*e3*4-((longlong)e1+e3-e2)*((longlong)e1+e3-e2);returnnum/(4.0*e3);}std::stringsolve(intx,inty,intr,conststd::vector<int>&t1,conststd::vector<int>&t2,conststd::vector<int>&t3){longr2=r*r;longd1=distance_p2(x,y,t1[0],t1[1]),d2=distance_p2(x,y,t2[0],t2[1]),d3=distance_p2(x,y,t3[0],t3[1]);//if one of the vertices is on the circleif(d1==r2||d2==r2||d3==r2)return"YES";//if all vertices is inside the circleif(d1<r2&&d2<r2&&d3<r2)return"NO";//if there exist at least two vertices, one inside the circle and the other on the outside of the circleif((d1<r2||d2<r2||d3<r2)&&(d1>r2||d2>r2||d3>r2))return"YES";//all vertices should be outside of the circle now//if the nearest point of t1-t2 (from (x,y)) is inside (or on) the circleif(distance_to_line_p2(x,y,t1[0],t1[1],t2[0],t2[1])<=r2)return"YES";//else all points of t1-t2 is outside the circleif(distance_to_line_p2(x,y,t1[0],t1[1],t3[0],t3[1])<=r2)return"YES";if(distance_to_line_p2(x,y,t2[0],t2[1],t3[0],t3[1])<=r2)return"YES";return"NO";}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Sherlock and Geometry
You are viewing a single comment's thread. Return to all comments →
OwO