Clock (几何题)

这是一个几何问题,目标是在一个矩形内部,已知多个圆的位置,通过二分法找到能够放置的最大圆的半径,新圆不能与原有的圆相交。检查包括将圆放在角落、与墙和一个圆相切、与两个圆相切这三种情况。解决方案涉及了复杂数学计算和浮点数精度处理。
摘要由CSDN通过智能技术生成
题意是 在一个矩形内,有多个圆,求还能放下的最大的一个圆的半径.这个圆不能与原有的重叠.

二分法枚举半径r,对于每个半径为r的圆

枚举3种情况,圆在四个角落,圆与一个圆和一边相切,圆与2个圆相切 得到坐标x,y

这个位于x,y的半径为r的圆不能与其他的圆相交...

最终找到符合要求的最大的圆...

 

官方的题解:

◮ Binary search on the radius of the clock
◮ To check if a clock with radius nr fits, there are 3 possibilities
for its centre-point:
◮ Place it in the corner of the wall, so at (nr , nr ), (W − nr , nr ),
(nr ,H − nr ) or (W − nr ,H − nr )
◮ New clock touching the wall and a clock i , at most 2 possible
centre-points per pair of wall and clock
◮ For wall with y = 0, the clock must be at y = nr , so solve the
equation (xi − x)2 + (yi − nr )2 == (ri + nr )2 for x
◮ New clock touching 2 clocks i and j , at most 2 possible
centre-points per pair of clocks
◮ Solve (xi − x)2 + (yi − y)2 == (ri + nr )2 and
(xj − x)2 + (yj − y)2 == (rj + nr )2 for x and y
◮ For each possible centre-point, check if it does not overlap
with the walls or other clocks
◮ This leads to an O(C3 log(min(W,H))) solution

对于与两个圆相切的求坐标的方法

http://paulbourke.net/geometry/2circle/

 

代码:

有点乱...    还有就是check()函数里的c1,c2 参数是必须的,可能因为浮点数运算精度会有问题,所以检查时要把基准的圆排除掉

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值