Tempo necessario per incontrarsi nel triangolo equilatero

Tempo necessario per incontrarsi nel triangolo equilatero

Data la lunghezza dei lati del triangolo equilatero (s) e la velocità (v) di ciascun animale segnato sui vertici del triangolo, determinare il tempo trascorso il quale si incontrano se iniziano a muoversi verso il loro opposto destro formando una traiettoria.
 

Tempo necessario per incontrarsi nel triangolo equilatero


Esempi:  

Ingresso: s = 2 v = 5
Produzione: 0,266667

Ingresso: s = 11 v = 556
Produzione: 0,013189


 


Approccio: 
Per trovare il tempo totale impiegato dagli animali per incontrarsi, prendi semplicemente A diviso per la velocità iniziale con cui due vertici si avvicinano l'uno all'altro. Scegli due vertici qualsiasi e puoi vedere che il primo punto si muove nella direzione del secondo alla velocità v mentre il secondo si muove nella direzione del primo (basta prendere la componente lungo uno dei bordi del triangolo). 
Riferimento : StackExchange
 

Di seguito è riportata l’implementazione dell’approccio di cui sopra:

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
      // PHP code to find time    // taken by animals to meet   // function to calculate   // time to meet   function   timeToMeet  (  $s     $v  )   {   $V   =   3   *   $v   /   2  ;   $time   =   $s   /   $V  ;   echo   $time  ;   }   // Driver Code   $s   =   25  ;   $v   =   56  ;   timeToMeet  (  $s     $v  );   // This code is contributed by anuj_67.   ?>   
JavaScript
    <  script  >   // JavaScript code to find time taken by animals   // to meet      // function to calculate time to meet      function     timeToMeet  (  s          v  )     {      var     V     =     3     *     v     /     2  ;      var     time     =     s     /     V  ;      document  .  write  (     time  .  toFixed  (  6  ));      }      // Driver Code      var     s     =     25       v     =     56  ;      timeToMeet  (  s       v  );   // This code is contributed by todaysgaurav     <  /script>   

Produzione
0.297619 

Complessità temporale: O(1)
Spazio ausiliario: O(1)

Crea quiz