QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#10512. PKUSC

Statistics

Kaguya is a girl who loves playing games.

Recently, she has been playing a hack-and-slash game where there are $n$ enemies on a plane, with each enemy at coordinates $(x_i, y_i)$. Kaguya has a skill that allows her to draw a simple polygon with $m$ vertices on the plane and eliminate all enemies that are strictly inside the polygon.

It is easy to see that to eliminate enemies quickly, one could simply draw a sufficiently large simple polygon. However, this would make the game less interesting. Therefore, Kaguya decides to add some randomness to the game.

Kaguya draws a simple polygon with $m$ vertices $(a_i, b_i)$ on the plane. Next, she chooses an angle $\alpha$ uniformly at random from $[-\pi, \pi)$ and rotates this simple polygon counter-clockwise around the origin by $\alpha$ radians.

Given the coordinates of each enemy and the vertices of the polygon, your task is to help Kaguya calculate the expected number of enemies she will eliminate after the random rotation.

Input

The first line contains two integers $n$ and $m$.

The next $n$ lines each contain two integers $x_i, y_i$, describing the coordinates of an enemy.

The next $m$ lines each contain two integers $a_i, b_i$, describing the vertices of the simple polygon in counter-clockwise order.

Output

Output a single real number representing the expected value, rounded to five decimal places. It is guaranteed that the 6th decimal place will not be 4 or 5 before rounding.

Examples

Input 1

4 4
0 0
1 0
-1 -1
0 1
0 0
1 0
1 1
0 1

Output 1

0.50000

Note

If you are not familiar with probability and expectation, here are some hints:

  1. Let $P_i$ be the probability that exactly $i$ enemies are eliminated after the rotation. The expectation is $\sum_{i=1}^n iP_i$.
  2. One way to calculate $P_i$ is to observe that among all rotation angles in $[-\pi, \pi)$, the angles that result in exactly $i$ enemies being eliminated form $t_i$ intervals $(l_j, r_j)$ (the openness/closedness of the intervals does not matter). Then $P_i = \frac{\sum_{j=1}^{t_i}(r_j - l_j)}{2\pi}$.

In this problem: the intervals where 0 enemies are eliminated are $[\frac{\pi}{2}, \pi)$ and $[-\pi, -\frac{\pi}{2}]$, and the intervals where 1 enemy is eliminated are $(-\frac{\pi}{2}, 0)$ and $(0, \frac{\pi}{2})$. Thus $P_0 = P_1 = \frac{1}{2}$. The answer is $\frac{1}{2} = 0.50000$.

Subtasks

For $30\%$ of the data, $n, m \leq 15$.

For another $30\%$ of the data, the chosen simple polygon is a convex polygon.

For $100\%$ of the data, $n \leq 200, m \leq 500, |x|, |y| \leq 10^6$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.