Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Paiza {
- protected function getInput() {
- $array = [];
- while ($line = fgets(STDIN)) {
- if ($line !== '') {
- $array[] = trim($line);
- }
- }
- $input = [];
- foreach ($array as $key => $value) {
- $input[] = explode(" ", $value);
- }
- return $input;
- }
- protected function println($str) {
- echo $str."\n";
- }
- }
- class B046 extends Paiza {
- private $circles;
- private $circle_from;
- private $direction_from;
- private $circle_to;
- private $direction_to;
- public function __construct() {
- $input = parent::getInput();
- $this->circles = $input[0][0];
- $this->circle_from = $input[1][0];
- $this->direction_from = $input[1][1];
- $this->circle_to = $input[2][0];
- $this->direction_to = $input[2][1];
- }
- public function main() {
- if ($this->direction_from === $this->direction_to) {
- parent::println(abs($this->circle_from - $this->circle_to) * 100);
- exit;
- }
- if (preg_match('/^(NS|SN|WE|EW)$/', $this->direction_from.$this->direction_to)) {
- parent::println(abs($this->circle_from + $this->circle_to) * 100);
- exit;
- } else {
- $circle_outer = max($this->circle_from, $this->circle_to);
- $circle_inner = min($this->circle_from, $this->circle_to);
- $distances = [];
- for ($r = $circle_inner; $r <= $circle_outer; $r++) {
- $distances[] = ($r * 100 * M_PI / 2) + abs($this->circle_from - $this->circle_to) * 100;
- }
- parent::println(min($distances));
- exit;
- }
- }
- }
- $b046 = new B046();
- $b046->main();
Add Comment
Please, Sign In to add comment