題目描述
對於兩個格子座標(x1,y1),(x2,y2)的歐幾里得距離爲:
( (x1-x2) * (x1-x2) + (y1-y2) * (y1-y2) ) 的算術平方根
小易想知道最多可以放多少塊蛋糕在網格盒子裏。
<?php
$handler = fopen('php://stdin','r');
$arr = explode(' ',fgets($handler));
function cal($w,$h) {
//發現規律,四行就一個週期
//第1、2行蛋糕的個數跟列關係爲:(h/4)*2 + h%4>2?2:h%4
//第3、4行蛋糕的個數跟列關係爲:(h/4)*2 + h%4<2?0:h%4-2
//多出的行要加上
$s = floor($w/4) * ((floor($h/4)*2 + ($h%4>2 ? 2 : $h%4) + floor($h/4)*2 + ($h%4<2 ? 0 : $h%4-2))) * 2;
if ($w%4 > 0) $s += floor($h/4)*2 + ($h%4>2 ? 2 : $h%4);
if ($w%4 > 1) $s += floor($h/4)*2 + ($h%4>2 ? 2 : $h%4);
if ($w%4 > 2) $s += floor($h/4)*2 + ($h%4<2 ? 0 : ($h%4-2));
echo $s;
}
cal($arr[0],$arr[1]);