CIRCLES2 - EDITORIAL

Can anyone please tell where am i going wrong. I have calculated distance between two centers of the circles + radius of circle1, if this is <= radius of circle2 then answer will be no otherwise yes. Point C can be any point, firstly checked if (x1+r1,y1) is possible then (x1-r1,y1), then (x1,y1+r1) and finally (x1, y1-r1) and center also.

https://www.codechef.com/viewsolution/26008763

1 Like

can you please have a look at my code.I think you will understand it.

that case has been handled.Could you please help me with the code

Helloā€¦ could you please take a look to my code as well and help me outā€¦

Link : CodeChef: Practical coding for everyone
please brother if you can help meā€¦ I have put in 10+ attempts over this question ; still I cannot figure out what the mistake isā€¦

Please ā€¦ Thanks in advanceā€¦

Helloā€¦ could you please take a look to my code as well and help me outā€¦

Link : CodeChef: Practical coding for everyone
please brother if you can help meā€¦ I have put in 10+ attempts over this question ; still I cannot figure out what the mistake isā€¦

Please ā€¦ Thanks in advanceā€¦!

You are missing the case when there is two point intersection and all the other four points lie inside the bigger circle.

this is not a good programming practice to define a macro with the name of an existing data type. like #define int long long

For answering only yes or noā€¦
Just checking this is enoughā€¦
If R1+distance(Center1, Center2) > R2 yes, else no

Can you find what is wrong with my approach:-
MY APPROACH IS TO CHECK FOR ONLY THESE 4 POINTS
that is
lx=x1-r;
ly=y1;
rx=x1+r;
ry=y1;
ux=x1;
uy=y1+r1;
dx=x1;
dy=y1-r;
IF ANY OF THESE POINTS SATISFIES THE CONDITION THEN RETURN TRUE AND write the required point else no code is given below:-----

PLEASE TELL ME WHERE I AM GOING WRONG IN MY APPROACH:-

#include<bits/stdc++.h>

using namespace std;
int main()
{
long long int i,j,k,l,m,n,o,p,q,r,t,x1,x2,y1,y2,r1,r2;
double rx,ry,lx,ly,ux,uy,dx,dy,ld,rd,ud,dd,ld1,rd1,ud1,dd1,rr1,rr2;
cin>>t;
while(tā€“)
{
cin>>x1>>y1>>r1>>x2>>y2>>r2;
lx=x1-r;
ly=y1;
rx=x1+r;
ry=y1;
ux=x1;
uy=y1+r1;
dx=x1;
dy=y1-r;
ld=((pow(lx-x1,2)+pow(ly-y1,2)));
ld1=((pow(lx-x2,2)+pow(ly-y2,2)));
rr1=pow(r1,2);
rr2=pow(r2,2);
if(ld<=rr1&&ld1>rr2)
{
cout<<ā€œYES\nā€;
printf("%.40lf %.40lf\n",lx,ly);
continue;
}
rd=((pow(rx-x1,2)+pow(ry-y1,2)));
rd1=((pow(rx-x2,2)+pow(ry-y2,2)));
if(rd<=rr1&&rd1>rr2)
{
cout<<ā€œYES\nā€;
printf("%.40lf %.40lf\n",rx,ry);
continue;
}
ud=((pow(ux-x1,2)+pow(uy-y1,2)));
ud1=((pow(ux-x2,2)+pow(uy-y2,2)));
if(ud<=rr1&&ud1>rr2)
{
cout<<ā€œYES\nā€;
printf("%.40lf %.40lf\n",ux,uy);
continue;
}
dd=((pow(dx-x1,2)+pow(dy-y1,2)));
dd1=((pow(dx-x2,2)+pow(dy-y2,2)));
if(dd<=rr1&&dd1>rr2)
{
cout<<ā€œYES\nā€;
printf("%.40lf %.40lf\n",dx,dy);
continue;
}
cout<<ā€œNO\nā€;
}
return 0;
}

Can someone please help me out

Did you get the answer ? I think the test cases were weak as that point would not be strictly outside the second circle.

Testerā€™s solution will give you WA, use double instead of int . I had a hard time figuring out why is this solution giving WA :relieved: .

@taran_1407
I have 2 solution(s) :slight_smile:

  1. which uses the formula for intersection of line and circle, this method involves too much calculation and gives WA :frowning:

Other solution uses trig. and it gives AC as it only does 2 calculationsā€¦

Logic of both solutions is ditto same.

So, we should do as less calculations as possible in geometry problems to not get WA?

What about the solution using (x2*(n+m) - x3*m)/n to calculate the x coordinate (similarly for y coordinate) ? I think this is the most efficient one. I tried using C++ trigo functions (tan() and atan()) but I ended up getting WA every time (even after taking care of precision).

double theta = Math.atan2(y2-y1, x2-x1);
double x3 = x1-r1Math.cos(theta), y3 = y1-r1Math.sin(theta);
if(dist(x3, y3, x2, y2) - r2 > eps){
pn(ā€œYESā€);
print(x3, y3);
}else pn(ā€œNOā€);
}
this case can work for all circles then why are you taking extra two cases,like if the center is same and y1<y2 ,y1+r1>y2+r2 ??
the angle pointed by yellow line must be subtracted from 180?
r1sin(Īø) and r1cos(Īø) will just give the distance ,how you are calculating the points in 2d co-ordinates?

Could not solve the problem during competition, felt my solution to calculate points is simpler:

Case-1: c1 and c2 has 0 or 1 common point, required point can be center of c1
Case-2: c1 completely inside c2, no solution
Case-3: c2 completely inside c1, and both circles are concentric, take center+sqrt(radius) for both x and y coordinates
Case-4: c1 and c2 are non-concentric; and intersecting at 2 points, use external section formula to find point in circumference of c1 farthest from c2

Hope it helps

In the editorials you have mentioned r1cos(theta) and r1sin(theta) provides the (x,y) coordinates of the target point C. It provides the point with respect to the center of the circle being (0,0) the origin. I think the translation of the target point C with respect to the center of the first circle (C1x, C1y) is missed in the editorials. Please correct me if Iā€™m wrong.

Where to learn geometry to be able to solve such problems?