0
点赞
收藏
分享

微信扫一扫

CF 303B(Rectangle Puzzle II-离矩形中心欧几里德距离最小的点)

罗子僧 2022-10-25 阅读 156


B. Rectangle Puzzle II



time limit per test

memory limit per test

input


output

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).

(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 ≤ x1 ≤ x ≤ x2 ≤ n, 0 ≤ y1 ≤ y ≤ y2 ≤ m

CF 303B(Rectangle Puzzle II-离矩形中心欧几里德距离最小的点)_#include

.

x1, y1, x2, y2



CF 303B(Rectangle Puzzle II-离矩形中心欧几里德距离最小的点)_#include_02


(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


n, m, x, y, a, b (1 ≤ n, m ≤ 109, 0 ≤ x ≤ n, 0 ≤ y ≤ m, 1 ≤ a ≤ n, 1 ≤ b ≤ m).


Output


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 test(s)


input


9 9 5 5 2 1


output


1 3 9 7


input


100 100 52 50 46 56


output


17 8 86 92


Note


The first sample has been drawn on the picture above.



德艺双馨柯老师看错题目卖队友。


这题是求在(0,0)(n,m)中的横边和竖边比为a:b,边平行坐标轴的矩形。


使其:


1.中心尽可能离(x,y)的欧几里德距离近。


2.面积尽量大


3.x1,y1,x2,y2字典序最小


前面的优先级高


如上是柯黑的翻译:


实际上2和1的位置是对调的……


于是,呵呵了



#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cstring>
#include<cctype>
#include<ctime>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define Forp(x) for(int p=pre[x];p;p=next[p])
int gcd(int a,int b){if (!b) return a;return gcd(b,a%b);}
int main()
{
int n,m,x,y,a,b,a1,b1;
cin>>n>>m>>x>>y>>a>>b;a1=a,b1=b;
int g=gcd(a,b);a/=g,b/=g;
int wid=n/a,hig=m/b;wid=min(wid,hig);
int x1=0,x2=wid*a,y1=0,y2=wid*b;
int del=x-x2/2-(x2%2),del2=x+x2/2;
if (del2>n) del-=(del2-n),del2=n;
if (del>=0&&del2<=n) x1+=del,x2+=del;
del=y-y2/2-(y2%2),del2=y+y2/2;
if (del2>m) del-=(del2-m),del2=m;
if (del>=0&&del2<=m) y1+=del,y2+=del;
cout<<x1<<' '<<y1<<' '<<x2<<' '<<y2<<endl;
return 0;
}



举报

相关推荐

0 条评论