Computer Science, asked by saibachu888, 9 months ago

VUIISIOTT COUrse
- Problem Description
On a busy road, multiple cars are passing by. A simulation is run to see what happens if brakes fail for all cars on the road. The only way for them to be safe is if they don't collide and pass
by each other. The goal is to identify whether any of the given cars would collide or pass by each other safely around a Roundabout. Think of this as a reference point o ( Origin with
coordinates (0,0)), but instead of going around it, cars pass through it.
Considering that each car is moving in a straight line towards the origin with individual uniform speed. Cars will continue to travel in that same straight line even after crossing origin
Calculate the number of collisions that will happen in such a scenario.
Note : - Calculate collisions only at origin. Ignore the other collisions. Assume that each car continues on its respective path even after the collision without change of direction or speed
for an infinite distance.
Constraints
1<=C<=1015
-10^9 <= x,y<= 10^9
0 <y< 10^9.
Input Format
The first line contains an integer C, denoting the number of cars being considered that are passing by around the origin.
Next C lines contain 3 space delimited values, first two of them being for position coordinates (x,y) in 2D space and the third one for speed (v).
Output
A single integer Q denoting the number of collisions at origin possible for given set of cars.
Timeout
DLL​

Answers

Answered by poojan
0

Answer:

Language used : Python Programming

I have attached the captures of the program and it's execution below, to show you the execution.

Formulae used:

Let the three input parameters be a,b,c where a is the x co-ordinate, b is the y coordinate and c is the speed.

As passage is through the Origin (0,0), The formula we use to calculate the distance is

\sqrt (a^{2} +b^{2} )

Speed= Distance / Time\\Time = Distance / Speed\\Time =( \sqrt(a^{2} +b^{2} ) ) / c

On finding the time period of each co-ordinate pair provided, to reach the origin, compare the time each of them takes. If you find the time period of any among them same, it means, those pairs lead to collision formation.

Program:

import math

n=int(input())

count=1

x=[]

y=[]

l=[]

for i in range(n):

   a,b,c=input().split(" ")

   l=[int(a),int(b),int(c)]

   x.append(l)

for i in x:

   t=(math.sqrt((i[0]**2)+(i[1]**2)))/i[2]

   #To find each time period, you can place a statement of print(t) over here.

   print("For coordinates ( ",i[0],i[1],i[2]," ), time to reach (0,0) is ",t)

   if t not in y:

       y.append(t)

   else:

       count=count+1

x.clear()

y.clear()

print("No.of collisions occur : ", count)

Input:

5

5 12 1

16 63 5

-10 24 2

7 24 2

-24 7 2

Output:

For coordinates (  5 12 1  ), time to reach (0,0) is  13.0

For coordinates (  16 63 5  ), time to reach (0,0) is  13.0

For coordinates (  -10 24 2  ), time to reach (0,0) is  13.0

For coordinates (  7 24 2  ), time to reach (0,0) is  12.5

For coordinates (  -24 7 2  ), time to reach (0,0) is  12.5

No.of collisions occur :  4

Further Explanation :

As we see, the time periods of first three is same: So, they three collide with each other respectively as in 1&2, 1&3, 2&3 collisions occur, and as the alst two are same, they two collide, as in 4&5 leads a collision. As there are totally four collisions occur, the output should be 4.

Note:

In the exam, we were not asked to provide time period and no.of collisions statement, so, we can remove the statement and compile to get 4.

So, That's it, pops!

Attachments:
Similar questions