405372: GYM101917 E Perfect Polygon

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

E. Perfect Polygontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Diego is looking through a window of size W*H and he wonders if given that particular window if there exists a perfect polygon for it. The answer is obviously yes, because perfection is relative to a specific metric. Diego decides that the polygon will be considered perfect if it's impossible to increase its width and height without leaving the window. Diego already has a polygon but he doesn't really like it that much, so first he will rotate it counterclockwise by some angle A, and then adjust the overall width and height of the polygon in order to make it fit perfectly within the window. In other words, given some polygon P you have to rotate it A degrees counterclockwise and then scale values in the x axis of the polygon to make sure that the point with the lowest x value is in position 0 and the biggest x is in position W, then do the same for the ys, but now the biggest is in position H.

Input

Four integers A, W, H, and N ($$$0<=A<=359, 1<=W,H<=10{^9}$$$, and $$$3<=N<=10{^5}$$$), the angle (in degrees) to rotate the polygon, the width and height of the window, and amount of points the polygon has. Then N lines with 2 integers each, the x and y ($$$0<=x,y<=10{^9}$$$) position of the ith point. The polygon may be concave and self-intersecting. You are guaranteed the polygon has area.

Output

N pair of numbers (1 pair per line), the x and y position of the ith point in the original polygon after applying the rotation and fitting the polygon to the window. You answer will be considered right if the relative or absolute error doesn't exceed $$$10{^-6}$$$.

ExampleInput
0 5 5 4
1 1
0 1
0 0
1 0
Output
5.000000000 5.000000000
0.000000000 5.000000000
0.000000000 0.000000000
5.000000000 0.000000000

Source/Category

加入题单

算法标签: