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
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
• 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
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
E Clocks
- Clock (几何题)
- UVA 579 (暑假-几何 A - Clock Hands)
- clock
- clock
- clock
- Clock
- CLOCK
- clock
- Clock
- clock
- clock
- CLOCK
- clock
- Clock
- Clock
- clock
- Clock
- Clock
- 13种提高系统伸缩性的最佳实践
- 云计算操作系统灭掉CMDB带来的哲学思考
- 有骨有肉的模型驱动架构-iModel模型驱动开发平台
- Effective C# 第二版 中文 之02
- sql server2005 无法修改表,超时时间已到 在操作完成之前超时时
- Clock (几何题)
- u-boot-2010.12移植到2440(yaffs2文件系统移植)
- 【转】Spring3.1 添加了cache支持
- 呃
- Java基础复习2_1(2011 06 10)
- 查询QQ号码是否在线
- 【Drupal】一些常用的主题函数备忘
- 【web开发】IE web cookiet 访问原理
- 高效管理ASP.NET的JavaScript库