情人节又快到了,每到这个时候总是 FFF 团最忙碌的时候,他们为了让社会更加和谐,致力于降低社会的狗粮度。
在一个 n*m 影院中,有 x 个男生和 y 个女生,保证 x + y = n * m, 如果有男女相邻或者前后而坐,狗粮度就会增加1,
现在他们已经黑入了影院的订票系统,想请你重新设置每个人的位置,使得影院的狗粮度最低。
Input
多组测试。每组输入形如:
n m x y
1<=n, m<=200
Output
每组输出形如:
ans
Sample Input
2 2 1 3 4 4 3 13
Sample Output
2 4
HINT
Source
两种方法都算取较小值
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#define eps 1e-8
const int INF = 0x3f3f3f3f;
const int N=105;
using namespace std;
int n,m,x,y;
int aa()
{
int a=min(n,m);
int b=min(x,y);
if(b==0)
return 0;
if(a==1)
return 1;
if(b%a==0)
return a;
else if(b<a)
return b+1;
else if(b>a)
return a+1;
}
int bb()
{
int l=min(x,y);
int t=(int)sqrt((double)l);
if(t*t==l).
return 2*t;
if(l-t*t<=t)
return 2*t+1;
return 2*t+2;
}
int main()
{
while(~scanf("%d%d%d%d",&n,&m,&x,&y))
{
int u=min(aa(),bb());
printf("%d\n",u);
}
}