Firing the Phaser
Time limit3sMemory limit512 MB
Given up to 15 non-touching axis-parallel rectangles and a beam length, find a start point and direction of a segment of that length that touches the most rectangles.
- Level
Medium7 of 10
- Topics
- Geometry, Brute force, Implementation
- Solved
- No attempts yet
Statement
You are the captain of a spaceship and have snuck up on the most fierce enemy you have ever faced. You plan to fire a large phaser cannon at the enemy flagship before it notices you. There is no room for error, so the shot must be perfect.
You have started charging the phaser and pulled the room layout of the flagship from the archives. You are directly above the enemy, and the layout is a two-dimensional map of rooms. Each room is a rectangle with sides parallel to the x and y axes, and no two rooms intersect, not even at a single point.
The phaser beam is set by a point and an angle . The beam starts at and travels a distance in the direction , damaging every room it touches. Your goal is to hit as many rooms as possible with one shot.
The charge is almost complete, and the only thing left is choosing the best setting. That turns out to be harder than expected. You have ten seconds until the charge finishes, so you write a program to solve it.
Input
The first line contains two integers and (, ), where is the number of rooms in the flagship and is the length of a phaser shot.
The next lines each contain four integers , , , (, ). Each line describes a room whose lower left corner is and whose upper right corner is .
Output
Output one line with the maximum number of rooms that one phaser beam can hit. A room counts as hit if the beam touches it.
You may assume the answer is numerically stable: if every room is expanded by in all four directions, the answer does not change.