Given two circles: O1 with the center o1 = (xo1, yo1) and a radius r1and O2 with the center o2 = (xo2, yo2) and radius r2, please compute if O1 is inside O2 or if O2 is inside O1.
Input description
First t < 1000, the number of test cases. In each of the following t lines, 6 integers: xo1 yo1 r1xo2 yo2 r2.Where 0 ≤ xo1, yo1,xo2, yo2 ≤ 10000and 0 < r1, r2 ≤ 10000.
Output description
For each test case print one character:
I, if O1 is inside O2 (or if O2 is inside O1),
E, if O1 is internally tangent to O2 (or if O2 is internally tangent to
O1),
O, in other cases.
Example
Input: 2 103 104 5 100 100 10 103 104 10 100 100 10 Output: E O
思路:包含在内部o1o2 < |r1-r2|;内切o1o2=|r1-r2|
代码如下
<?php
$debug = true;
$file = STDIN;
if ($debug)
{
$file = fopen('./spoj.txt', 'r');
}
$t = fgets($file);
$t = trim($t);
while ($t--)
{
$line = trim(fgets($file));
$data = explode(' ', $line);
$x1 = intval($data[0]);
$y1 = intval($data[1]);
$r1 = intval($data[2]);
$x2 = intval($data[3]);
$y2 = intval($data[4]);
$r2 = intval($data[5]);
$dis = sqrt(pow($x1 - $x2, 2) + pow($y1 - $y2, 2));
if (abs($r1 - $r2) == $dis) echo 'E', PHP_EOL;
else if ($dis < abs($r1 - $r2)) echo 'I', PHP_EOL;
else echo 'O', PHP_EOL;
}
if ($debug) fclose($file);
?>