A9035 | Rectangle Puzzle II
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
The first line contains six integers $n,m,x,y,a,b$ $(1<=n,m<=10^{9},0<=x<=n,0<=y<=m,1<=a<=n,1<=b<=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})$ .
输入输出样例
输入 #1
9 9 5 5 2 1
输出 #1
1 3 9 7
输入 #2
100 100 52 50 46 56
输出 #2
17 8 86 92
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted