Computer Science, asked by uday115611, 10 months ago

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

Answers

Answered by poojan
1

COLLISION COUNT PROBLEM :

Language used : Python Programming

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:

Optional :  [ 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

Explanation :

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.

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.

Learn more :

  • Advantages of Programming in python

       brainly.in/question/11007952

  • Indentation is must in python. Know more about it at :

       brainly.in/question/17731168

Attachments:
Similar questions