BNUOJ 1095 Business Cards

CEPC 2008

感觉这题看了题解也不太懂。。

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int gcd(int a,int b)
{
    int t;
    if (a < b)
    {
        t=a;
        a=b;
        b=t;
    }
    if (b == 0)
        return a;
    else
        return gcd(b,a%b);
}
bool check(int a,int b,int c)
{
    int i;
    if (a < b)
    {
        i=a;
        a=b;
        b=i;
    }
    if (c%a == 0)
        return true;
    for (i=c; i>=0; i-=a)
    {
        if (i%b == 0)
            return true;
    }
    return false;
}
int main()
{
    int prob,a,b,n,m,c;
    scanf("%d",&prob);
    while (prob--)
    {
        scanf("%d%d%d%d",&a,&b,&m,&n);
        c=gcd(a,b);
        if (m%c != 0 || n%c != 0)
        {
            printf("NO\n");
            continue;
        }
        if ((m%a == 0 && n%b == 0) ||(m%b == 0 && n%a == 0))
        {
            printf("YES\n");
            continue;
        }
        a/=c;
        b/=c;
        m/=c;
        n/=c;
        if (m%a == 0 && m%b == 0 && check(a,b,n) == true)
            printf("YES\n");
        else if (n%a == 0 && n%b == 0 && check(a,b,m) == true)
            printf("YES\n");
        else
            printf("NO\n");
    }
}

你可能感兴趣的:(BNUOJ 1095 Business Cards)