Beispiel #1
0
        }
        while ($i > 0 && $j > 0 && ($i % $j != 0 && $j % $i != 0)) {
            if ($who_is_no_move == 1) {
                $this->moveArya($i, $j);
            } else {
                $this->moveBran($i, $j);
            }
            $who_is_no_move = -$who_is_no_move;
        }
        return $i > 0 && $j > 0 && $who_is_no_move == 1 ? 1 : 0;
    }
    public function solve($plot)
    {
        $winning_pos = 0;
        for ($i = (int) $plot[0]; $i <= (int) $plot[1]; $i++) {
            for ($j = (int) $plot[2]; $j <= (int) $plot[3]; $j++) {
                var_dump("------{$i} -- {$j}------");
                $winning_pos += $this->isWinning($i, $j);
            }
        }
        return $winning_pos;
    }
}
$task = new Task1();
list($handle, $T) = $task->getTestCases("C-small-practice.in");
file_put_contents('output.out', '');
for ($i = 0; $i < $T; $i++) {
    $plot = $task->getNextTestCase($handle);
    $result = $task->solve($plot);
    $task->appendResult($i + 1, $result);
}
Beispiel #2
0
            }
        }
        return array($R_OK, $B_OK);
    }
    public function appendResult($T, $result)
    {
        if ($result[0] == false & $result[1] == false) {
            $word = 'Neither';
        }
        if ($result[0] == true & $result[1] == false) {
            $word = 'Red';
        }
        if ($result[0] == false & $result[1] == true) {
            $word = 'Blue';
        }
        if ($result[0] == true & $result[1] == true) {
            $word = 'Both';
        }
        $text = "Case #{$T}: " . $word;
        file_put_contents('output.out', $text . "\n", FILE_APPEND);
    }
}
$task = new Task1();
list($handle, $T) = $task->getTestCases("A-large-practice.in");
file_put_contents('output.out', '');
for ($i = 0; $i < $T; $i++) {
    list($handle, $board, $N, $K) = $task->getNextTestCase($handle);
    $board = $task->simulateRotation($board, $N);
    $result = $task->whoWins($board, $N, $K);
    $task->appendResult($i + 1, $result);
}