#P4276. 封兽鵺的激光游戏

封兽鵺的激光游戏

Description

With your help, Suika finally delivered all the invitations in a single day.

Night falls. As the fireworks provided by Nitori Kawashiro shoot into the sky with a “whoosh,” the grand banquet begins right on time.

In an instant, the huge venue fills with laughter and joy: Suika and Yuugi drink and chat, the smell of alcohol wafting around; Patchouli and Alice each pull one of Marisa’s arms, arguing about which side to explore first; Cirno and Daiyousei are scribbling on the ground, working on math problems... Everything feels harmonious and perfect.

However, as the party gets livelier, Suika, the host, still feels like something is missing. After a moment, she realizes she forgot to prepare a game. What is a party without games? To fix this serious problem, Suika puts down her gourd and asks Houjuu Nue for help.

This gives Nue a headache! Only good at causing chaos and pixelating things, she ponders hard and finally comes up with a good idea. She takes out some of her UFOs, then borrows a few laser beams from Byakuren Hijiri. The game rules set by Houjuu Nue are as follows:

Houjuu Nue places some solid, uniformly dense UFOs on the plane (each can be regarded as a convex polygon). Due to her limited ability, each UFO has at most five edges. You can fire a laser from a given point in any direction (0° along the positive x-axis, 90° along the positive y-axis; the launch angle is guaranteed to have two decimal places, i.e., the laser rotates from 0° in steps of 0.01°). When the laser hits the boundary of a UFO, it reflects. Each time it reflects, the energy increases by w (initial energy is 0). Note that once an edge is hit by the laser once, it loses its reflective ability and becomes a transparent edge. After that, your laser can pass directly into the interior of a UFO and reflect from the inside.

If you still don’t understand, Houjuu Nue has thoughtfully prepared the following diagram:

Originally, chaos-loving Nue wanted the laser’s energy to be as large as possible at exit, but Suika worried about damage to the venue and changed the goal to “energy closest to an integer E.” To ensure difficulty, before the game starts, Nue will rotate each UFO clockwise about its centroid by k * 90°.

Now it’s your turn to play. If the angle you choose matches Nue’s answer, you will receive two prizes—100 points and Houjuu Nue’s photo book!

Of course, since you have a computer, you won’t try angles one by one. You will solve the problem by programming in advance, and when it’s time to play, you will use the optimal angle to win.

Input Format

  • The first line contains an integer n, the number of UFOs.
  • The next n lines: each line starts with an integer m, followed by m pairs of real numbers x[i], y[i], giving the m vertices of that UFO in clockwise order.
  • The next n lines: each contains an integer k, meaning this UFO is rotated clockwise by k * 90° about its centroid.
  • The next line contains two integers w and E, the energy increment per reflection and the target integer to approach.
  • The last line contains two real numbers x0, y0, the laser’s emission point.

Output Format

Output a real number d, rounded to two decimal places, the emission angle that makes the laser’s exit energy closest to E. If multiple angles satisfy the requirement, output the smallest angle.

2
4 0 0 0 4 4 4 4 0
3 8 0 12 4 12 0
0 
0
1 2
5 5
300.97

Hint

Sample explanation: As shown in the figure, when the emission angle is 300.97°, the laser reflects exactly twice. The energy is 2 * w, which equals E, so it meets the requirement.

Things you must pay special attention to:

  1. When a laser hits a UFO’s vertex, it is not considered a collision.
  2. Polygons do not overlap. The initial emission point is not on or inside any UFO.
  3. Don’t talk science here: the laser can enter the interior of a UFO and reflect inside.

Constraints:

Rewards:

(Yes, it’s a ZUN illustration photo book. If you AC this problem, you can get it.)

Translated by ChatGPT 5