codingame/FACILE/Défibrillateurs/script.php
2015-03-02 19:42:39 +01:00

53 lines
933 B
PHP

<?php
/**
* Auto-generated code below aims at helping you parse
* the standard input according to the problem statement.
**/
fscanf(STDIN, "%s",
$LON
);
fscanf(STDIN, "%s",
$LAT
);
fscanf(STDIN, "%d",
$N
);
$defibs = [];
for ($i = 0; $i < $N; $i++)
{
$defibs[] = explode(';', stream_get_line(STDIN, 256, "\n"));
}
$key = null;
$distance = null;
function f($s) {
return (float) str_replace(',', '.', $s);
}
$la1 = f($LAT);
$lo1 = f($LON);
foreach ($defibs as $k => $defib) {
$la2 = f($defib[5]);
$lo2 = f($defib[4]);
$x = ($lo2 - $lo1) * cos(($la1 + $la2) / 2);
$y = ($la2 - $la1);
$d = sqrt($x*$x + $y*$y) * 6371;
if (null === $distance || $d < $distance) {
$distance = $d;
$key = $k;
}
}
// Write an action using echo(). DON'T FORGET THE TRAILING \n
// To debug (equivalent to var_dump): error_log(var_export($var, true));
echo $defibs[$key][1], "\n";
?>