We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
let we have n ants.
We have to maximize the Hi among them so We have to divide them equally into two groups n*(n-n/2).
Now Comes the main part We have Time= (10^9 + 6), so we will find the Encounter of ants only for 10^9 initially afterwords we count for 6. so Speed = 0.1 m/s , Length of Track = 1000, so Time taken by ants to complete one cycle = 1000/0.1 = 10000.
Total Time = 10^9
Number of Cycles = 10^9/10^4 = 10^5
Total Encounters = Number of Cycle * n*(n-n/2);
Now Came The Second Part:
The rest 6 sec.
if the distance between 2 ants is <6*0.1*2 then Only there will be Encounter. so we Wil iterate through the initial Position of ants and check that whether Two ants are standing <1.2m distance or not, it they increase the Encounter +1;
PS. Sort the Array and Check the last index and the first index are also at the distance less than 1.2 , then increase the Counter;
Finally Return the total Encounter * 2 as in One Encounter there will be Two Hi
Ants
You are viewing a single comment's thread. Return to all comments →
Explanation goes:
let we have n ants. We have to maximize the Hi among them so We have to divide them equally into two groups n*(n-n/2). Now Comes the main part We have Time= (10^9 + 6), so we will find the Encounter of ants only for 10^9 initially afterwords we count for 6. so
Speed = 0.1 m/s ,
Length of Track = 1000,
so Time taken by ants to complete
one cycle = 1000/0.1 = 10000.
Total Time = 10^9
Number of Cycles = 10^9/10^4 = 10^5
Total Encounters = Number of Cycle * n*(n-n/2);
Now Came The Second Part:
The rest 6 sec. if the distance between 2 ants is <6*0.1*2 then Only there will be Encounter. so we Wil iterate through the initial Position of ants and check that whether Two ants are standing <1.2m distance or not, it they increase the Encounter +1;
PS. Sort the Array and Check the last index and the first index are also at the distance less than 1.2 , then increase the Counter;
Finally Return the total Encounter * 2 as in One Encounter there will be Two Hi
Implementation in Cpp: