CF303B.Rectangle Puzzle II

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

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

Your task is to find a maximum sub-rectangle on the grid (_x_1, _y_1, _x_2, _y_2) 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 ≤ _x_1 ≤ x ≤ _x_2 ≤ n, 0 ≤ _y_1 ≤ y ≤ _y_2 ≤ m, .

The sides of this sub-rectangle should be parallel to the axes. And values _x_1, _y_1, _x_2, _y_2 should be integers.

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 (_x_1, _y_1, _x_2, _y_2), so we can choose the lexicographically minimum one.

给你一个矩形网格,其尺寸为 n×mn \times m。我们在此网格上建立坐标系,因此网格上的每个点都有坐标——一对整数 (x,y)(x, y)(其中 0≤x≤n0 \le x \le n,0≤y≤m0 \le y \le m)。

你的任务是在该网格中找出一个面积最大的子矩形 (x1,y1,x2,y2)(x_1, y_1, x_2, y_2),使得该子矩形包含给定点 (x,y)(x, y),且其长宽比恰好为 (a,b)(a, b)。换言之,需满足以下条件:
0≤x1≤x≤x2≤n0 \le x_1 \le x \le x_2 \le n,
0≤y1≤y≤y2≤m0 \le y_1 \le y \le y_2 \le m,
。

该子矩形的边必须与坐标轴平行,且 x1,y1,x2,y2x_1, y_1, x_2, y_2 均为整数。

若存在多个解,则选择最接近(x,y)(x, y) 的矩形。“最接近”指 (x,y)(x, y) 到该矩形中心的欧几里得距离最小。若仍有多个解,则选择字典序最小的一个。“字典序最小”是指将子矩形视为整数序列 (x1,y1,x2,y2)(x_1, y_1, x_2, y_2),从中选出字典序最小者。

输入格式

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

第一行包含六个整数 nn、mm、xx、yy、aa、bb(1 ≤ n, m ≤ 1091 \le n, m \le 10^9,0 ≤ x ≤ n0 \le x \le n,0 ≤ y ≤ m0 \le y \le m,1 ≤ a ≤ n1 \le a \le n,1 ≤ b ≤ m1 \le b \le m)。

输出格式

Print four integers _x_1, _y_1, _x_2, _y_2, which represent the founded sub-rectangle whose left-bottom point is (_x_1, _y_1) and right-up point is (_x_2, _y_2).

输出四个整数 x1, y1, x2, y2x_1,\ y_1,\ x_2,\ y_2,它们表示所找到的子矩形,其左下角点为 (x1, y1)(x_1,\ y_1),右上角点为 (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

输入解题思路,AI测评打分。不知道怎么写?

首页