예제 #1
0
            }
            if ($v[$r][$left] >= $ww) {
                $newcoord = $r;
                $w = FALSE;
                $ww = $v[$r][$left];
            }
            if ($v[$right][$r] >= $ww) {
                $newcoord = $r;
                $w = TRUE;
                $ww = $v[$right][$r];
            }
        }
        if ($w) {
            $result[] = $r;
            $right = $r;
        } else {
            array_unshift($result, $r);
            $left = $r;
        }
        $remaining = array_filter($remaining, function ($u) use($r) {
            return $u != $r;
        });
    }
    return $result;
}
$n = intval(readline_fix(''));
$v = array();
for ($i = 0; $i != $n; ++$i) {
    $v[$i] = explode(' ', readline_fix(''));
}
print implode(' ', p($n, $v)) . "\n";
예제 #2
0
{
    $str = readline($a);
    readline($a);
    return $str;
}
/*
while (($str = readline_fix('')) !== FALSE)
{
	print('['.$str.']'."\n");
}
*/
$c = intval(readline_fix(''));
for (; $c; --$c) {
    $n = intval(readline_fix(''));
    $astr = readline_fix('');
    $wstr = readline_fix('');
    /*
    print('['.$astr.']'."\n");
    print('['.$wstr.']'."\n");
    */
    $as = explode(' ', $astr);
    $ws = explode(' ', $wstr);
    $opts = array();
    for ($i = 0; $i != $n; ++$i) {
        $a = intval($as[$i]);
        $w = intval($ws[$i]);
        /*
        print($a.' '.$w."\n");
        */
        $opts =& x($opts, $a, $w);
    }