📜  遇到等边三角形所需的时间

📅  最后修改于: 2021-04-26 11:02:59             🧑  作者: Mango

给定等边三角形的边长和在三角形顶点上标记的每只动物的速度(v),请找出它们相遇的时间(如果它们开始向右对边移动,形成一条轨迹)。

3

例子:

Input : s = 2, v = 5
Output : 0.266667

Input : s = 11, v = 556
Output : 0.013189

方法 :
要找到动物相遇所需的总时间,只需将A除以两个顶点相互接近的初始速率即可。选取任意两个顶点,可以看到第一个点以速度v在第二个点的方向上移动,而第二个点在第一个点的方向上移动(只需沿一个三角形边缘取分量)。
参考:StackExchange

C++
// CPP code to find time
// taken by animals to meet
#include 
using namespace std;
 
// function to calculate time to meet
void timeToMeet(double s, double v){
 
     double V = 3 * v / 2;
           
     double time = s / V;
      
     cout << time;
}
 
// Driver Code
int main(void) {
     
    double s = 25, v = 56;
     
    timeToMeet(s, v);
     
    return 0;
}


Java
// Java code to find time taken by animals
// to meet
import java.io.*;
 
public class GFG {
 
    // function to calculate time to meet
    static void timeToMeet(double s, double v){
     
        double V = 3 * v / 2;
             
        double time = s / V;
         
        System.out.println((float)time);
    }
     
    // Driver Code
    static public void main (String[] args)
    {
         
        double s = 25, v = 56;
     
        timeToMeet(s, v);
    }
}
 
//This code is contributed by vt_m.


Python3
# Python3 code to find time
# taken by animals to meet
 
# function to calculate
# time to meet
def timeToMeet(s, v):
    V = 3 * v / 2;
     
    time = s / V;
     
    print(time);
 
# Driver Code
s = 25;
v = 56;
     
timeToMeet(s, v);
     
# This code is contributed by mits


C#
// C# code to find time
// taken by animals to meet
using System;
 
public class GFG {
     
    // function to calculate time to meet
    static void timeToMeet(double s, double v){
     
        double V = 3 * v / 2;
             
        double time = s / V;
         
        Console.WriteLine((float)time);
    }
     
    // Driver Code
    static public void Main ()
    {
         
        double s = 25, v = 56;
     
        timeToMeet(s, v);
     
    }
}
 
// This code is contributed by vt_m.


PHP


Javascript


输出:

0.297619