#P5467. Expected Enemy Elimination under Random Polygon Rotation
Expected Enemy Elimination under Random Polygon Rotation
Expected Enemy Elimination under Random Polygon Rotation
A game character, Jiutiao Kelin, uses a special skill in her favorite "grass‐cutting" game. In the game, there are \( n \) enemies located on the plane with coordinates \( (x_i, y_i) \) for \( 1 \le i \le n \). Jiutiao Kelin initially draws a simple polygon with \( m \) vertices \( (a_i, b_i) \) (the vertices are given in order and the polygon does not intersect itself). She then randomly picks an angle \( \alpha \) uniformly from \( [-\pi, \pi) \) and rotates the polygon counterclockwise about the origin by \( \alpha \) (in radians). The skill eliminates all enemies that are strictly inside the rotated polygon.
Help Jiutiao Kelin compute the expected number of enemies eliminated. In other words, for each enemy, compute the probability (over the uniformly random rotation) that the enemy is strictly inside the rotated polygon and sum these probabilities over all enemies.
Note: If an enemy lies exactly on the boundary of the polygon after rotation, it is not eliminated.
Hint: For an enemy at \( (x,y) \) (with polar coordinates \( (r, \theta) \)), note that the event that this enemy is inside the rotated polygon \( R(P,\alpha) \) is equivalent to the event that the point \( R(-\alpha)(x,y) \) lies inside the original polygon \( P \). As \( \alpha \) is uniformly distributed over \( [-\pi,\pi) \), the probability that the enemy is eliminated can be computed as \[ \frac{1}{2\pi}\cdot \text{measure}\Big\{\beta \in [-\pi,\pi): (r\cos\beta, r\sin\beta) \in P \Big\}. \] For a fixed radius \( r \), the set of angles for which \( (r\cos\beta, r\sin\beta) \in P \) can be determined by computing the intersection of the circle of radius \( r \) (centered at the origin) with the polygon \( P \).
inputFormat
The first line contains two integers \( n \) and \( m \) \( (1 \le n, m \le 10^4) \): the number of enemies and the number of polygon vertices.
The next \( n \) lines each contain two real numbers \( x_i \) and \( y_i \), the coordinates of the \( i\text{-th} \) enemy.
The next \( m \) lines each contain two real numbers \( a_i \) and \( b_i \), the coordinates of the vertices of the polygon in order. The polygon is simple (its edges do not cross) and the vertices are given in either clockwise or counterclockwise order.
outputFormat
Output a single real number, the expected number of enemies eliminated. An answer is accepted if it has an absolute or relative error of no more than \( 10^{-6} \).
sample
3 3
0 0
2 0
-2 0
1 1
-1 1
0 -1
1.0000000000