Cherry83

8.Trip Length v.1

Feb 9th, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.65 KB | None | 0 0
  1. <?php
  2.  
  3. function Distance($x1, $y1, $x2, $y2)
  4. {
  5.     return sqrt(pow($x1 - $x2, 2) + pow($y1 - $y2, 2));
  6. }
  7.  
  8. list($x1, $y1, $x2, $y2, $x3, $y3) = explode(", ", trim(fgets(STDIN)));
  9.  
  10.  
  11. $d['a'] = Distance($x1, $y1, $x2, $y2);
  12. $d['b'] = Distance($x2, $y2, $x3, $y3);
  13. $d['c'] = Distance($x1, $y1, $x3, $y3);
  14.  
  15. asort($d);
  16. //print_r($d);
  17.  
  18. $n = array_slice($d,0,2, true);
  19. ksort($n);
  20. $k = array_keys($n);
  21.  
  22. $sum = $n[$k[0]]+$n[$k[1]];
  23.  
  24. //print_r($n);
  25. //print_r($k);
  26.  
  27. if (!array_key_exists('a',$n)){
  28.     echo "1->3->2";
  29. }
  30. if (!array_key_exists('b',$n)){
  31.     echo "2->1->3";
  32. }
  33. if (!array_key_exists('c',$n)){
  34.     echo "1->2->3";
  35. }
  36. echo ": $sum";
Advertisement
Add Comment
Please, Sign In to add comment