Count of collisions at a point ( X , Y ) | C # program to implement the above approach ; 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
using System ; using System . Collections ; class GFG { static double solve ( int [ , ] D , int N , int X , int Y ) { ArrayList T = new ArrayList ( ) ; for ( int i = 0 ; i < N ; i ++ ) { int x = D [ i , 0 ] ; int y = D [ i , 1 ] ; double speed = D [ i , 2 ] ; double time = ( ( x * x - X * X ) + ( y * y - Y * Y ) ) / ( speed * speed ) ; T . Add ( time ) ; } T . Sort ( ) ; int j = 0 ; int total = 0 ; while ( j < ( T . Count - 1 ) ) { int count = 1 ; while ( ( j < ( T . Count - 1 ) ) && ( Convert . ToDouble ( T [ j ] ) . CompareTo ( Convert . ToDouble ( T [ j + 1 ] ) ) == 0 ) ) { count += 1 ; j += 1 ; } total += ( count * ( count - 1 ) ) / 2 ; j += 1 ; } return total ; } public static void Main ( String [ ] args ) { int N = 5 ; int [ , ] D = new int [ , ] { { 5 , 12 , 1 } , { 16 , 63 , 5 } , { - 10 , 24 , 2 } , { 7 , 24 , 2 } , { - 24 , 7 , 2 } } ; int X = 0 , Y = 0 ; Console . WriteLine ( solve ( D , N , X , Y ) ) ; } }