Guest User

Untitled

a guest
Dec 15th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. <?php
  2.  
  3. class Paiza {
  4. protected function getInput() {
  5. $array = [];
  6. while ($line = fgets(STDIN)) {
  7. if ($line !== '') {
  8. $array[] = trim($line);
  9. }
  10. }
  11. $input = [];
  12. foreach ($array as $key => $value) {
  13. $input[] = explode(" ", $value);
  14. }
  15. return $input;
  16. }
  17. protected function println($str) {
  18. echo $str."\n";
  19. }
  20. }
  21.  
  22. class B046 extends Paiza {
  23. private $circles;
  24. private $circle_from;
  25. private $direction_from;
  26. private $circle_to;
  27. private $direction_to;
  28.  
  29. public function __construct() {
  30. $input = parent::getInput();
  31.  
  32. $this->circles = $input[0][0];
  33. $this->circle_from = $input[1][0];
  34. $this->direction_from = $input[1][1];
  35. $this->circle_to = $input[2][0];
  36. $this->direction_to = $input[2][1];
  37. }
  38.  
  39. public function main() {
  40. if ($this->direction_from === $this->direction_to) {
  41. parent::println(abs($this->circle_from - $this->circle_to) * 100);
  42. exit;
  43. }
  44. if (preg_match('/^(NS|SN|WE|EW)$/', $this->direction_from.$this->direction_to)) {
  45. parent::println(abs($this->circle_from + $this->circle_to) * 100);
  46. exit;
  47. } else {
  48. $circle_outer = max($this->circle_from, $this->circle_to);
  49. $circle_inner = min($this->circle_from, $this->circle_to);
  50. $distances = [];
  51. for ($r = $circle_inner; $r <= $circle_outer; $r++) {
  52. $distances[] = ($r * 100 * M_PI / 2) + abs($this->circle_from - $this->circle_to) * 100;
  53. }
  54. parent::println(min($distances));
  55. exit;
  56. }
  57. }
  58. }
  59.  
  60. $b046 = new B046();
  61. $b046->main();
Add Comment
Please, Sign In to add comment