Count of collisions at a point ( X , Y ) | Function to find the count of possible pairs of collisions ; Stores the time at which points reach the origin ; Calculate time for each point ; Sort the times ; Counting total collisions ; Count of elements arriving at a given point at the same time ; Driver Code ; Given set of points with speed ; Function Call
def solve ( D , N , X , Y ) : NEW_LINE INDENT T = [ ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT x = D [ i ] [ 0 ] NEW_LINE y = D [ i ] [ 1 ] NEW_LINE speed = D [ i ] [ 2 ] NEW_LINE time = ( ( x * x - X * X ) + ( y * y - Y * Y ) ) / ( speed * speed ) NEW_LINE T . append ( time ) NEW_LINE DEDENT T . sort ( ) NEW_LINE i = 0 NEW_LINE total = 0 NEW_LINE while i < len ( T ) - 1 : NEW_LINE INDENT count = 1 NEW_LINE while i < len ( T ) - 1 and T [ i ] == T [ i + 1 ] : NEW_LINE INDENT count += 1 NEW_LINE i += 1 NEW_LINE DEDENT total += ( count * ( count - 1 ) ) / 2 NEW_LINE i += 1 NEW_LINE DEDENT return total NEW_LINE DEDENT N = 5 NEW_LINE D = [ [ 5 , 12 , 1 ] , [ 16 , 63 , 5 ] , [ - 10 , 24 , 2 ] , [ 7 , 24 , 2 ] , [ - 24 , 7 , 2 ] ] NEW_LINE X = 0 NEW_LINE Y = 0 NEW_LINE print ( solve ( D , N , X , Y ) ) NEW_LINE