Given length of sides of equilateral triangle (s), and velocities(v) of each animal tagged on the vertices of triangle, find out the time after which they meet, if they start moving towards their right opposite, forming a trajectory.

Examples:
Input: s = 2, v = 5
Output: 0.266667
Input: s = 11, v = 556
Output: 0.013189
Approach :
To find the total amount of time taken for the animals to meet, simply take A divided by the initial rate at which two vertices approach each other. Pick any two vertices, and it can be seen that the first point moves in the direction of the second at speed v, while the second moves in the direction of the first (just take the component along one of the triangle edges).
Reference : StackExchange
Below is the implementation of the above approach:
C++
#include <bits/stdc++.h>
using namespace std;
void timeToMeet( double s, double v){
double V = 3 * v / 2;
double time = s / V;
cout << time ;
}
int main( void ) {
double s = 25, v = 56;
timeToMeet(s, v);
return 0;
}
|
Java
import java.io.*;
public class GFG {
static void timeToMeet( double s, double v){
double V = 3 * v / 2 ;
double time = s / V;
System.out.println(( float )time);
}
static public void main (String[] args)
{
double s = 25 , v = 56 ;
timeToMeet(s, v);
}
}
|
Python3
def timeToMeet(s, v):
V = 3 * v / 2 ;
time = s / V;
print (time);
s = 25 ;
v = 56 ;
timeToMeet(s, v);
|
C#
using System;
public class GFG {
static void timeToMeet( double s, double v){
double V = 3 * v / 2;
double time = s / V;
Console.WriteLine(( float )time);
}
static public void Main ()
{
double s = 25, v = 56;
timeToMeet(s, v);
}
}
|
PHP
<?php
function timeToMeet( $s , $v )
{
$V = 3 * $v / 2;
$time = $s / $V ;
echo $time ;
}
$s = 25; $v = 56;
timeToMeet( $s , $v );
?>
|
Javascript
<script>
function timeToMeet(s , v) {
var V = 3 * v / 2;
var time = s / V;
document.write( time.toFixed(6));
}
var s = 25, v = 56;
timeToMeet(s, v);
</script>
|
Time complexity: O(1)
Auxiliary space: O(1)