Ejemplo n.º 1
0
<?php

//Тестер
/*
	По каналу связи передаются сообщения, каждое из которых содержит 16 букв А, 8 букв Б, 4 буквы В и 4 буквы Г (других букв в сообщениях нет). Каждую букву кодируют двоичной последовательностью. При выборе кода учитывались два требования: 
	а) ни одно кодовое слово не является началом другого (это нужно, чтобы код допускал однозначное декодирование);
	б) общая длина закодированного сообщения должна быть как можно меньше.
	Какой код из приведённых ниже следует выбрать для кодирования букв А, Б, В и Г?
	1) А:0, Б:10, В:110, Г:111
	2) А:0, Б:10, В:01, Г:11
	3) А:1, Б:01, В:011, Г:001
	4) А:00, Б:01, В:10, Г:11
*/
header('Content-Type: text/html; charset=utf-8');
require_once "Task1.php";
$task1 = new Task1();
//Задаём варианты задачи
// 1-st set
$codeArray = array();
array_push($codeArray, array("А" => "0"));
array_push($codeArray, array("Б" => "10"));
array_push($codeArray, array("В" => "110"));
array_push($codeArray, array("Г" => "111"));
$task1->setData($codeArray);
// 2-nd set
$codeArray = array();
array_push($codeArray, array("А" => "0"));
array_push($codeArray, array("Б" => "10"));
array_push($codeArray, array("В" => "01"));
array_push($codeArray, array("Г" => "11"));
$task1->setData($codeArray);
Ejemplo 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);
}
Ejemplo n.º 3
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);
}
Ejemplo n.º 4
0
 public function testFizzBuzzBazz()
 {
     $task1 = new Task1();
     $this->assertTrue($task1->fizzBuzzBazz(4, 11));
 }
Ejemplo n.º 5
0
<?php

class Task1
{
    public function getTestCases($filename)
    {
        $handle = fopen($filename, "r");
        $T = (int) fgets($handle);
        return array($handle, $T);
    }
    public function getNextTestCase($handle)
    {
        return trim(fgets($handle));
    }
    public function appendResult($T, $result)
    {
        $text = "Case #{$T}: " . $result;
        file_put_contents('output.out', $text . "\n", FILE_APPEND);
    }
}
$task = new Task1();
list($handle, $T) = $task->getTestCases("B-large-practice.in");
file_put_contents('output.out', '');
for ($i = 0; $i < $T; $i++) {
    $msg = $task->getNextTestCase($handle);
    $task->appendResult($i + 1, implode(" ", array_reverse(explode(" ", $msg))));
}
Ejemplo n.º 6
0
<?php

/**
 * Created by PhpStorm.
 * User: Jundat95
 * Date: 12/24/2015
 * Time: 8:41 AM
 */
class Task1
{
    private $age;
    private $name;
    public function __construct($name)
    {
        $this->name = $name;
    }
    public function getAge()
    {
        return $this->age;
    }
    public function setAge($age)
    {
        if ($age <= 20) {
            throw new Exception('Tuoi nhap vao phai > 20.');
        }
        $this->age = $age;
    }
}
$task1 = new Task1('Doan Tinh');
$task1->setAge(30);
var_dump($task1->getAge());
Ejemplo n.º 7
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));
}