入门赛B题求调
  • 板块学术版
  • 楼主11514zbs
  • 当前回复11
  • 已保存回复11
  • 发布时间2024/7/19 21:28
  • 上次更新2024/7/19 23:06:48
查看原帖
入门赛B题求调
1125106
11514zbs楼主2024/7/19 21:28

暴力:

#include <cstdio>
int main()
{
    long long x, y, z, w, c = 0;
    scanf("%lld %lld %lld %lld", &x, &y, &z, &w);
    for (; c <= x || c <= y; c++)
    {
        if (z * c == x && w * c == y)
        {
            break;
        }
    }
    if (z * c == x || w * c == y)
    {
        printf("%lld\n", c);
    }
    else
    {
        printf("-1\n");
    }
    return 0;
}

分类讨论:

#include <cstdio>
int main()
{
    int x, y, z, w;
    scanf("%d %d %d %d", &x, &y, &z, &w);
    if ((z == 0 && x != 0) || (w == 0 && y != 0))
    {
        printf("-1");
    }
    else if ((z == 0 && x == 0) && (y % w == 0))
    {
        printf("%d", y / w);
    }
    else if ((y == 0 && w == 0) && (x % z == 0))
    {
        printf("%d", x / z);
    }
    else if (x == 0 && y == 0)
    {
        printf("0");
    }
    else if ((x == 0 && y != 0) || (x != 0 && y == 0))
    {
        printf("-1");
    }
    else if ((x % z != 0) || (y % w != 0))
    {
        printf("-1");
    }
    else if (x / z == y / w)
    {
        printf("%d", x / z);
    }
    else if (x / z != y / w)
    {
        printf("-1");
    }
    return 0;
}

有没有大神帮忙看看,蒟蒻都卡在#9了QwQ

2024/7/19 21:28
加载中...