Clock (几何题)

来源:互联网 发布:淘宝上不发货怎么退款 编辑:程序博客网 时间:2024/04/29 17:02

题意是 在一个矩形内,有多个圆,求还能放下的最大的一个圆的半径.这个圆不能与原有的重叠.

二分法枚举半径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 参数是必须的,可能因为浮点数运算精度会有问题,所以检查时要把基准的圆排除掉

Description

During the past few years Tim E. has been collecting circle-shaped clocks and he exposed them on a big wall in his living room. He wants to buy another big clock, but because his wall is almost full he wants to know what the radius of the biggest clock is that could be exposed on the wall without overlapping any other clock.
The wall is modelled as a rectangle with width W and height H. For each clock the coordinates (xi, yi) of the centre-point and the radius ri are given. The clocks will not overlap with the boundaries of the wall, nor will two clocks overlap, however they might touch each other.

Input

The first line of the input contains a single number: the number of test cases to follow. Each test case has the following format:
• One line with two integers W and H satisfying 1 ≤ W,H ≤ 1, 000, 000: the width and the height of the wall, respectively.
• One line with an integer C satisfying 0 ≤ C ≤ 50: the number of clocks.
• C lines, each with three integers xi, yi and ri satisfying ri > 0, 0 ≤ xi − ri, xi + ri ≤ W, 0 ≤ yi − ri and yi + ri ≤ H: the location and radius of an existing clock.

Integers on the same line are separated by single spaces. For any pair of clocks i and j (i = j), (xi − xj)^2 + (yi − yj)^2 ≥ (ri + rj)^2.

Output

For every test case in the input, the output should contain a single real number, on a single line: the maximum radius of a clock that fits on the wall without overlapping with any existing clock
or the boundaries of the wall.
You need to print the result with 4 digits of precision, round half up. You may use printf ("%.4lf/n", M); .

Sample Input

110 1042 2 12 8 18 2 18 8 1

Sample Output

3.2426
BAPC 2010
E Clocks
原创粉丝点击