Esempio n. 1
0
        }
        return $rev_mapping;
    }
    public function solve($msg)
    {
        $out = '';
        $reverse_mapping = $this->revMapping();
        $prev = null;
        $msg_l = strlen($msg);
        for ($i = 0; $i < $msg_l; $i++) {
            if ($prev) {
                $a = $reverse_mapping[$prev];
                if ($a[strlen($a) - 1] == $reverse_mapping[$msg[$i]][0]) {
                    $out .= ' ';
                }
            }
            $out .= $reverse_mapping[$msg[$i]];
            $prev = $msg[$i];
        }
        return $out;
    }
}
$task = new Task1();
list($handle, $T) = $task->getTestCases("C-small-practice.in");
file_put_contents('output.out', '');
for ($i = 0; $i < $T; $i++) {
    $msg = $task->getNextTestCase($handle);
    $result = $task->solve($msg);
    var_dump($result);
    $task->appendResult($i + 1, $result);
}
Esempio n. 2
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);
}
Esempio n. 3
0
        $products = explode(" ", trim(fgets($handle)));
        return array($total_sum, $products);
    }
    public function appendResult($T, $result)
    {
        $text = "Case #{$T}: " . $result;
        file_put_contents('output.out', $text . "\n", FILE_APPEND);
    }
    public function solve($total_sum, $products)
    {
        // rsort($products);
        $products_count = count($products);
        for ($i = 0; $i < $products_count; $i++) {
            for ($j = $i + 1; $j < $products_count; $j++) {
                if ($products[$i] + $products[$j] == $total_sum) {
                    return array($i + 1, $j + 1);
                }
            }
        }
    }
}
$task = new Task1();
list($handle, $T) = $task->getTestCases("A-large-practice.in");
file_put_contents('output.out', '');
// $T = 1;
for ($i = 0; $i < $T; $i++) {
    list($total_sum, $products) = $task->getNextTestCase($handle);
    $result = $task->solve($total_sum, $products);
    // var_dump($result);
    $task->appendResult($i + 1, implode(" ", $result));
}