4356: 情人节的阻击

情人节又快到了,每到这个时候总是 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

lyf

两种方法都算取较小值

#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);
    }
}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值