アルゴリズムのアウトプット
ということで、
レッドコーダーが教える、競プロ・AtCoder上達のガイドライン【中級編:目指せ水色コーダー!】@e869120さん
AtCoder で水色コーダー、つまりレーティング 1200 を少ない問題数で達成するために、茶色コーダー・緑コーダーにとって適切な教育的良問を 100 問集めました。
こちらの記事の初中級者が解くべき過去問精選 100 問
をPHPで解いていきます。
<?php
while (true) {
$s = trim(fgets(STDIN));
$s = str_replace(array("\r\n","\r","\n"), '', $s);
$s = explode(" ", $s);
$n = $s[0];
$x = $s[1];
if ($n == 0 && $x == 0) {
break;
}
$ans = 0;
for ($i = 1; $i <= $n; $i++) {
for ($j = 1; $j <= $n; $j++) {
for ($k = 1; $k <= $n; $k++) {
if ($i < $j && $j < $k && $i + $j +$k == $x) {
$ans++;
}
}
}
}
echo $ans . "\n";
}
典型的な全列挙の問題。