SPOJ15709 Two Circles

本文介绍了一种通过计算判断两个圆之间位置关系的方法,包括一个圆是否完全位于另一个圆内部、两圆是否内切以及其它情况。通过输入两个圆的中心坐标及半径,可以快速确定它们之间的相对位置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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);
?>

   


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kgduu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值