Ejemplo n.º 1
0
for ($k = 1; $k <= $cases; $k++) {
    $num = (int) fgets($handle);
    $str = trim(fgets($handle));
    $arr = explode(' ', $str);
    $av = array_count_values($arr);
    $av = quicksort($av);
    $c = count($av) - 1;
    $s = 0;
    for ($i = $c; $i >= 0; $i--) {
        $v = (int) $av[$i];
        if ($v == 1 && $i == $c) {
            echo "0\n";
            break;
        } else {
            if ($v > 1 && $i <= $c) {
                $s += shake($v);
            }
        }
    }
    if ($s) {
        echo $s * 2 . "\n";
    }
}
function quicksort($array)
{
    if (count($array) < 2) {
        return $array;
    }
    $left = $right = array();
    reset($array);
    $pivot_key = key($array);
Ejemplo n.º 2
0
<?php

// Take some limonade
require_once 'lib/limonade.php';
// Add the Fizzy
require_once 'lib/fizzy.php';
define('ROOT_DIR', realpath('../'));
define('CONFIG_FILE', ROOT_DIR . '/config.xml');
define('PAGES_FILE', ROOT_DIR . '/pages.xml');
define('VIEWS_DIR', ROOT_DIR . '/views/');
define('PUBLIC_DIR', ROOT_DIR . '/public/');
define('BASE_URL', '');
// shake it
shake();
// Fizzy Limonade!
Ejemplo n.º 3
0
        setcookie("logsession", $sessionID, 0, $boardroot, "", false, true);
        Query("INSERT INTO {sessions} (id, user, autoexpire) VALUES ({0}, {1}, {2})", doHash($sessionID . $salt), $user["id"], 0);
        redirectAction("board");
    }
}
$sexes = array(__("Male"), __("Female"), __("N/A"));
$name = "";
if (isset($_POST["name"])) {
    $name = htmlspecialchars($_POST["name"]);
}
$email = "";
if (isset($_POST["email"])) {
    $email = htmlspecialchars($_POST["email"]);
}
$sex = 2;
if (isset($_POST["sex"])) {
    $sex = validateSex($_POST["sex"]);
}
echo "\n<script src=\"" . resourceLink('js/register.js') . "\"></script>\n<script src=\"" . resourceLink('js/zxcvbn.js') . "\"></script>\n<form action=\"" . actionLink("register") . "\" method=\"post\">\n\t<table class=\"outline margin width50\">\n\t\t<tr class=\"header0\">\n\t\t\t<th colspan=\"2\">\n\t\t\t\t" . __("Register") . "\n\t\t\t</th>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td class=\"cell2\">\n\t\t\t\t<label for=\"un\">" . __("User name") . "</label>\n\t\t\t</td>\n\t\t\t<td class=\"cell0\">\n\t\t\t\t<input type=\"text\" id=\"un\" name=\"name\" value=\"{$name}\" maxlength=\"20\" style=\"width: 98%;\"  class=\"required\" />\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td class=\"cell2\">\n\t\t\t\t<label for=\"pw\">" . __("Password") . "</label>\n\t\t\t</td>\n\t\t\t<td class=\"cell1\">\n\t\t\t\t<input type=\"password\" id=\"pw\" name=\"pass\" size=\"13\" maxlength=\"32\" class=\"required\" /> / " . __("Repeat:") . " <input type=\"password\" id=\"pw2\" name=\"pass2\" size=\"13\" maxlength=\"32\" class=\"required\" />\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td class=\"cell2\">\n\t\t\t\t<label for=\"email\">" . __("Email address") . "</label>\n\t\t\t</td>\n\t\t\t<td class=\"cell0\">\n\t\t\t\t<input type=\"email\" id=\"email\" name=\"email\" value=\"{$email}\" style=\"width: 98%;\" maxlength=\"60\" />\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td class=\"cell2\">\n\t\t\t\t" . __("Sex") . "\n\t\t\t</td>\n\t\t\t<td class=\"cell1\">\n\t\t\t\t" . MakeOptions("sex", $sex, $sexes) . "\n\t\t\t</td>\n\t\t</tr>";
if ($haveSecurimage) {
    echo "\n\t\t<tr>\n\t\t\t<td class=\"cell2\">\n\t\t\t\t" . __("Security") . "\n\t\t\t</td>\n\t\t\t<td class=\"cell1\">\n\t\t\t\t<img width=\"200\" height=\"80\" id=\"captcha\" src=\"" . actionLink("captcha", shake()) . "\" alt=\"CAPTCHA Image\" />\n\t\t\t\t<button onclick=\"document.getElementById('captcha').src = '" . actionLink("captcha", shake()) . "?' + Math.random(); return false;\">" . __("New") . "</button><br />\n\t\t\t\t<input type=\"text\" name=\"captcha_code\" size=\"10\" maxlength=\"6\" class=\"required\" />\n\t\t\t</td>\n\t\t</tr>";
}
echo "\n\t\t<tr class=\"cell2\">\n\t\t\t<td></td>\n\t\t\t<td>\n\t\t\t\t<input type=\"submit\" name=\"action\" value=\"" . __("Register") . "\"/>\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td colspan=\"2\" class=\"cell0 smallFonts\">\n\t\t\t\t" . __("Specifying an email address is not exactly a hard requirement, but it will allow you to reset your password should you forget it. By default, your email is not shown.") . "\n\t\t\t</td>\n\t\t</tr>\n\t</table>\n</form>";
function MakeOptions($fieldName, $checkedIndex, $choicesList)
{
    $checks[$checkedIndex] = " checked=\"checked\"";
    foreach ($choicesList as $key => $val) {
        $result .= format("\n\t\t\t\t\t<label>\n\t\t\t\t\t\t<input type=\"radio\" name=\"{1}\" value=\"{0}\"{2} />\n\t\t\t\t\t\t{3}\n\t\t\t\t\t</label>", $key, $fieldName, $checks[$key], $val);
    }
    return $result;
}
Ejemplo n.º 4
0
<?php

$handle = fopen("input.txt", "r");
$cases = (int) fgets($handle);
for ($i = 1; $i <= $cases; $i++) {
    $n = (int) fgets($handle);
    echo shake($n) . "\n";
}
function shake($n)
{
    if ($n == 1) {
        return 0;
    }
    if ($n == 2) {
        return 1;
    }
    // if($n == 3)
    // 	return 3;
    $m = $n - 1;
    $odd = $m % 2;
    $even = round($m / 2, 0, PHP_ROUND_HALF_DOWN);
    $re = $even * $n;
    if ($odd == 0) {
        return $re;
    }
    if ($odd == 1) {
        $r = $even + 1;
        return $re + $r;
    }
}