https://ide.codingblocks.com/s/437581.
what is the error? plz provide me some test cases
MAXIMUM CIRCLE Problem
Consider this input output format:
Input:
4
1 1
4 1
5 2
7 1
Expected output:
1
I havent passed two test cases,whats the error?
itβs cause of wrong approach, follow this approach
- Find staring and ending points of the diameter of the circles.
- Starting point would be equal to (c-r) and ending point would be equal to (c+r) where (c, 0) is the center of the particular circle and r is its radius.
- Sort the {start, end} pair according to the value of end point. Less the value of end point, less is its index.
- Start iterating the pairs and if the starting point of a circle is less then current end value, it means circles are intersecting hence increment the count. Else update the current end value.
Note : Touching circles are also considered to be intersecting.
Not overlapping condtion of a circle is AB>=R1+R2, AB is the distance between the centres of the circle and R1 - radius of circle 1 and R2- radius of second circle, when this contion satisfies i am incrementing the res,and at last the min no of circles to be removed will be size of vector - res.
but you have to sort them as well using a comparator function
bool comp(circle a, circle b)
{
if (a.end == b.end)
return a.start < b.start;
return a.end < b.end;
}
Do this and then try to submit, it will get accepted.
I am asking about my approach (Not overlapping condtion of a circle is AB>=R1+R2, AB is the distance between the centres of the circle and R1 - radius of circle 1 and R2- radius of second circle, when this contion satisfies i am incrementing the res,and at last the min no of circles to be removed will be size of vector - res.) ? Whats wrong in that?
This is right
This should be AB>R1+R2
If we take intersection of two circles into consideration
Also, iterate over the pairs and if the starting point of a circle is less then current end value, it means circles are intersecting hence increment the count(you are doing this) you have to update the current end value if no intersection occurs to check for remaining pairs(but not this)