CF303B.Rectangle Puzzle II

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a rectangle grid. That grid's size is n×mn×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)(x,y) (0<=x<=n,0<=y<=m)(0<=x<=n,0<=y<=m) .

Your task is to find a maximum sub-rectangle on the grid (x1,y1,x2,y2)(x_{1},y_{1},x_{2},y_{2}) so that it contains the given point (x,y)(x,y) , and its length-width ratio is exactly (a,b)(a,b) . In other words the following conditions must hold: 0<=x1<=x<=x2<=n0<=x_{1}<=x<=x_{2}<=n , 0<=y1<=y<=y2<=m0<=y_{1}<=y<=y_{2}<=m , .

The sides of this sub-rectangle should be parallel to the axes. And values x1,y1,x2,y2x_{1},y_{1},x_{2},y_{2} should be integers.

If there are multiple solutions, find the rectangle which is closest to (x,y)(x,y) . Here "closest" means the Euclid distance between (x,y)(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)(x_{1},y_{1},x_{2},y_{2}) , so we can choose the lexicographically minimum one.

输入格式

The first line contains six integers n,m,x,y,a,bn,m,x,y,a,b (1<=n,m<=109,0<=x<=n,0<=y<=m,1<=a<=n,1<=b<=m)(1<=n,m<=10^{9},0<=x<=n,0<=y<=m,1<=a<=n,1<=b<=m) .

输出格式

Print four integers x1,y1,x2,y2x_{1},y_{1},x_{2},y_{2} , which represent the founded sub-rectangle whose left-bottom point is (x1,y1)(x_{1},y_{1}) and right-up point is (x2,y2)(x_{2},y_{2}) .

输入输出样例

  • 输入#1

    9 9 5 5 2 1
    

    输出#1

    1 3 9 7
    
  • 输入#2

    100 100 52 50 46 56
    

    输出#2

    17 8 86 92
    
首页