TopCoder SRM 629 题解

这篇博客主要解析了TopCoder SRM 629中的两道题目。题目A的解题关键在于判断木板是否能覆盖洞口,条件是木板的长和宽不能小于洞的长和宽。对于题目B,采用贪心策略,通过比较所有比值,找出期望与实际差值最小的答案。

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

题目A:

Problem Statement

 

There is a rectangular hole in the ground. You are given the dimensions of this rectangle: ints holeH and holeW.

You have a rectangular board. You are given its dimensions: ints boardH and boardW. You would like to use the board to cover the hole.

There are some rules you must follow when covering the hole:

  • You may rotate the board, but you must place it so that the sides of the board are parallel to the sides of the hole.
  • The board must cover the entire hole.
  • All corners of the board must be strictly outside the hole. (That is, they are not allowed to lie on the boundary of the hole.)

If you can cover the hole using the board you have, return 1. Otherwise, return -1.

Definition

 
Class: RectangleCoveringEasy
Method: solve
Parameters: int, int, int, int
Returns: int
Method signature: int solve(int holeH, int holeW, int boardH, int boardW)
(be sure your method is public)

Limits

 
Time limit (s): 2.000
Memory limit (MB): 256

Constraints

- holeW, holeH, boardW, and boardH will be between 1 and 1,000,000,000, inclusive.

Examples

0)  
 
1
1
1
1
Returns: -1
The vertices of the board must not be on the boundar
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值