Math, asked by shahdhruvi1112, 7 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 pallu723
3

Answer:

#include<math.h>

int collide(int n,int arr*){

int arr1[100000];

int i,j,k,l,count=0,dist=0,d,output=0;

int size_t=sizeof(arr)/sizeof(arr[0]);

for(i=0,j=1,k=2;(i<size_t-2)&&(j<size_t-1)&&(k<size_t);i++,j++,k++){

if(arr[i]<0){

arr[i]=0-arr[i];

}

else if(arr[j]<0){

arr[j]=0-arr[j];

}

d=(arr[i]*arr[i])+(arr[j]*arr[j]);

dist=sqrt(d);

arr1[count]=dist/arr[k];

}

for(l=0;l<i;i++){

for(j=1;j<i;j++){

if(arr1[l]==arr1[j]){

output++;

}

}

}

return output;

}

Explanation:

Just calculate the distance from the origin get time of collision and there you are

I know this code is not optimised and also that isn't being checked too I think

I am not participating I am just helping a friend so got to know about this platform.

Answered by cutebrainlyteacher72
0

upper answer is correct

Similar questions