3608.Rectangle Puzzle II

Time Limit: 1s Memory Limit: 256MB

You are given a rectangle grid. That grid's size is n \times m. Let's denote the coordinate system on the grid. So, each point on the grid will have coordinates - a pair of integers (x,y) (0 \le x \le n,0 \le y \le m).Your task is to find a maximum sub-rectangle on the grid (x1,y1,x2,y2) so that it contains the given point (x,y), and its length-width ratio is exactly (a,b). In other words the following conditions must hold: 0 \le x1 \le x \le x2 \le n, 0 \le y1 \le y \le y2 \le m, 3608_1.png.The sides of this sub-rectangle should be parallel to the axes. And values x1,y1,x2,y2 should be integers. 3608_2.png If there are multiple solutions, find the rectangle which is closest to (x,y). Here "closest" means the Euclid distance between (x,y) and the center of the rectangle is as small as possible. If there are still multiple solutions, find the lexicographically minimum one. Here "lexicographically minimum" means that we should consider the sub-rectangle as sequence of integers (x1,y1,x2,y2), so we can choose the lexicographically minimum one.

Input Format(From the terminal/stdin)

Input The first line contains six integers n,m,x,y,a,b (1 \le n,m \le 109,0 \le x \le n,0 \le y \le m,1 \le a \le n,1 \le b \le m).

Output Format(To the terminal/stdout)

Output Print four integers x1,y1,x2,y2, which represent the founded sub-rectangle whose left-bottom point is (x1,y1) and right-up point is (x2,y2).

Sample Input 1

Copy
9 9 5 5 2 1
 · · · · · \n

Sample Output 1

Copy
1 3 9 7
 · · · \n

Sample Input 2

Copy
100 100 52 50 46 56
   ·   ·  ·  ·  ·  \n

Sample Output 2

Copy
17 8 86 92
  · ·  ·  \n

Submit

请先 登录

© 2025 FAQs