情人节的阻击

版权声明:来自星空计算机团队(QQ群:134826825)——申屠志刚 https://blog.csdn.net/weixin_43272781/article/details/85784478

http://oj.acm.zstu.edu.cn/JudgeOnline/problem.php?id=4356

C++版本一

题解:找到男女少的一方设为X,将X尽量朝正方形形状排位置,如果最后矩形的短边大于电影院矩形短边的一半(省去小数部分),那么按照向下填充方法排位置,否则输出a+b。

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<string.h>
using namespace std;
 
int main(){
    int n,m,x,y,swa;
    while(~scanf("%d%d%d%d",&n,&m,&x,&y)){
        int ans1=0;
        if(n>m){
            swa=n;
            n=m;
            m=swa;
        }
        if(x>y){
            swa=x;
            x=y;
            y=swa;
        }
        if(x%n==0)ans1=n;
        else if(x/n==0)ans1=x+1;
        else ans1=n+1;
        if(x==0)ans1=0;
 
        int ans2,a=1,b=1;
        while(a*b<x){
            if(a>b)b++;
            else a++;
        }
        if(b>n/2){
            printf("%d\n",ans1);
            continue;
        }
        ans2=a+b;
        printf("%d\n",ans2);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_43272781/article/details/85784478