• Business Cards


    Problem Description
    Running a paper shop is not an easy job, especially with harsh customers. Today they brought their own rectangular sheets of paper, asking you to cut it into rectangular business cards of specific size.

    Moreover, they require that all the paper (which may not be cheap, but is definitely not that expensive!) has to be used, i.e. no tiny bit may be left over.
    Moreover, the brilliant idea of cutting the sheet into very small pieces, and then gluing them together in desired sheets was laughed at.

    An example of a 9 *6 paper sheet divided into 2 * 3 cards is given below.
     
    Input
    The input contains several test cases. The first line contains the number of test cases t (t <= 10^5). Then t test cases follow. Each of them consists of one line containing four integers a, b, c, d (1 <=a, b, c, d <= 10^9).

    Numbers a and b are dimensions of each business card; c and d are dimensions of the paper sheet.
     
    Output
    For each test case output one line containing word YES if it is possible to divide the whole sheet into business cards, and NO otherwise.
     
    Sample Input
    4 2 3 9 6 2 3 8 6 2 3 6 8 2 3 5 7
     
    Sample Output
    YES YES YES NO
     
    分析:
      好吧,这个是用了枚举,但问题是在使用枚举时,我们一定要知道要枚举的东西是什么,有哪些,要不然还真是没法做。好吧,这个是看了别人的代码才知道要枚举什么的。。。。
    因为所有碎片都是相同的矩形,所以当矩形排列横竖不同时,一行或列会能够整除小矩形的长和宽。
    #include<iostream>
    using namespace std;
    bool jud(int a, int b, int z) {
            int x = 1;
            while(a * x < z) {
                if((z - a * x) % b == 0) {
                    return true;
                }
                x++;
            }
            return false;
    }
    bool judge(int x,int y,int m,int n)
    {
        if(m % x==0 && n % y==0)
            return true;
        if(m % y==0 && n % x==0)
            return true;
        if(m % y==0 && m % x==0 && jud(x,y,n))
            return true;
        if(n % y==0 && n % x==0 && jud(x,y,m))
            return true;
        return false;
    }



    int main()
    {
        int n;
        while(cin>>n)
        {
            while(n--)
            {
                int x,y,m,n;
                cin>>x>>y>>m>>n;
                if(judge(x,y,m,n))
                    cout<<"YES"<<endl;
                else
                    cout<<"NO"<<endl;
            }
        }
        return 0;
    }

  • 相关阅读:
    composer安装Workerman报错:Installation failed, reverting ./composer.json to its original content.
    从零开始搭建linux下laravel 5.5所需环境(三)
    ASPNET Razor 使用 @Ajax.BeginForm 需要注意到的细节
    .NET跨平台
    1172金币
    1044电子表
    1358统计号码牌
    1355疫情防控 数据调查
    1056反向输出一个三位数2
    1071行李托运
  • 原文地址:https://www.cnblogs.com/zhaoxinshanwei/p/3675438.html
Copyright © 2020-2023  润新知