Sweep line

View as PDF

Submit solution

Points: 100
Time limit: 3.0s
Memory limit: 256M

Problem type

Marisa wants to run a sweep line algorithm on a set of points. In a sweep line algorithm, the point with the lowest x-value gets processed first, then the 2nd lowest x, then the 3rd, until the point with the highest x gets processed. If 2 points have the same x-value, then they the point with the lower y-value is processed first.

Marisa wonders how the order would change if all the points are rotated. If she rotates all points around the origin by ang degrees counterclockwise, what would be the x-value (after rotation) of the last point processed by a sweep line algorithm?

Since Marisa is studious, she has many values of ang for which she wants the x-value of last point processed.

Input

The first line has 2 integers, n, m, the number of points, and the number of values of ang

The next n lines each have 2 integers, x_i y_i, the x and y value of the ith point. All points are distinct.

The next m lines have one value, ang_i, a float which gives the amount in degrees the points are rotated by. Each value of ang_i represents an independent case, so do not apply rotations successively.

1 <= n <= 1e5

1 <= m <= 1e4

-1e4 <= x_i, y_i <= 1e4

0 <= ang_i < 360

Output:

For every value of ang_i, write one line with the answer for that query. The answer being the last x-value processed if the original points were rotated by ang_i degrees counterclockwise.

Sample Input:

3
0 0 
1 1
0 1

Sample Output:

0.2928931713

Sample Input:

4
1 1
3 1
3 4
1 4

Sample Output:

2

Sample Input:

5
0 0
1 0
1 1
0 2
-1 1

Sample Output:

0.1291712523

Comments

There are no comments at the moment.