题意是 在一个矩形内,有多个圆,求还能放下的最大的一个圆的半径.这个圆不能与原有的重叠.
二分法枚举半径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 参数是必须的,可能因为浮点数运算精度会有问题,所以检查时要把基准的圆排除掉