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.
this is my code which I wrote in 5-6 hours can someone point out what am i missing because this is really frustrating they have given a testcase and inside that testcase there are 30000 testcases :( instead they should have given 10 seprate testcases :(
#include<bits/stdc++.h>usingnamespacestd;//int dist();intdistance(intx,inty,intx1,inty1,intx2,inty2){floatx3=0.0,y3=0.0,temp=0.0,temp1=0.0;floatslope=(y2-y1)/(1.0*(x2-x1));//cout<<slope<<endl;temp=y1-y-x1*(slope)-x*(1.0/slope);temp1=-(1.0/slope)-slope;floatx_cor=temp/(1.0*temp1);floaty_cor=y1+slope*(x_cor-x1);floatdist=0.0;dist=(x-x_cor)*(x-x_cor)+(y-y_cor)*(y-y_cor);returndist;}// Complete the solve function below.stringsolve(intx,inty,intr,vector<int>t1,vector<int>t2,vector<int>t3){intcount1=0,count2=0,count3=0;if((t1[0]-x)*(t1[0]-x)+(t1[1]-y)*(t1[1]-y)<r*r)count1++;if((t2[0]-x)*(t2[0]-x)+(t2[1]-y)*(t2[1]-y)<r*r)count1++;if((t3[0]-x)*(t3[0]-x)+(t3[1]-y)*(t3[1]-y)<r*r)count1++;if((t1[0]-x)*(t1[0]-x)+(t1[1]-y)*(t1[1]-y)>r*r)count2++;if((t2[0]-x)*(t2[0]-x)+(t2[1]-y)*(t2[1]-y)>r*r)count2++;if((t3[0]-x)*(t3[0]-x)+(t3[1]-y)*(t3[1]-y)>r*r)count2++;if((t1[0]-x)*(t1[0]-x)+(t1[1]-y)*(t1[1]-y)==r*r)count3++;if((t2[0]-x)*(t2[0]-x)+(t2[1]-y)*(t2[1]-y)==r*r)count3++;if((t3[0]-x)*(t3[0]-x)+(t3[1]-y)*(t3[1]-y)==r*r)count3++;//cout<<count1<<" "<<count2<<endl;floatpoint_x=0.0,point_y=0.0,temp=0.0,dist=0.0;if(count3!=0)return"YES";if(count1==3)return"NO";if(count1==1&&count2==2)return"YES";if(count1==2&&count2==1)return"YES";elseif(count2==3){floatdist1=distance(x,y,t1[0],t1[1],t2[0],t2[1]);floatdist2=distance(x,y,t1[0],t1[1],t3[0],t3[1]);floatdist3=distance(x,y,t2[0],t2[1],t3[0],t3[1]);//float test4 = dist(4,0,0,0,4,4);if(dist1<=r*r*1.0)return"YES";if(dist2<=r*r*1.0)return"YES";if(dist3<=r*r*1.0)return"YES";elsereturn"NO";}elsereturn"YES";}intmain(){intt;cin>>t;vector<string>res;stringresult;for(inti=0;i<t;i++){intx,y,r;intx1,y1,x2,y2,x3,y3;vector<int>t1,t2,t3;cin>>x>>y>>r;cin>>x1>>y1;t1.push_back(x1);t1.push_back(y1);cin>>x2>>y2;t2.push_back(x2);t2.push_back(y2);cin>>x3>>y3;t3.push_back(x3);t3.push_back(y3);result=solve(x,y,r,t1,t2,t3);res.push_back(result);}for(inti=0;i<t;i++){cout<<res[i]<<endl;}return0;}
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 →
this is my code which I wrote in 5-6 hours can someone point out what am i missing because this is really frustrating they have given a testcase and inside that testcase there are 30000 testcases :( instead they should have given 10 seprate testcases :(