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

最新文章

  1. Android View 的事件体系
  2. 服务器上的json类型的文件提示找不到
  3. windows下安装yaf和git
  4. 怒刷DP之 HDU 1114
  5. Linux之父Linus Torvalds:讨厌C++
  6. liunx命令之whereis、which、find的区别和联系
  7. Gen_server行为分析与实践
  8. ThinkPHP CURD方法盘点:where方法
  9. iOS-UI控件精讲之UILabel
  10. 了解XSS攻击
  11. 各种数据库的批量插入操作_Oracle
  12. 文件队列 QueueFile
  13. UIBezierPath详解
  14. solr 学习之简介及安装
  15. Cocos2d-x 3.2 环境搭建
  16. MyBatis动态传入表名,字段名参数的解决办法
  17. Certificate downloaded from cloudexpress:11443 is invalid
  18. 什么是Docker??
  19. Python实现简单的三级菜单
  20. MySQL(索引)

热门文章

  1. drupal 用法小结,drupal select ,query ,distinct
  2. MySql LeftJoin On 与 Where的差异
  3. Appium客户端,命令行启动server
  4. SpringCloud 简单理解
  5. Ubuntu 16.04中VirtualBox 5.1使用U盘/USB设备的方法
  6. 如何使用eclipse搭建maven环境以及常见的错误
  7. 使用CSS实现透明边框的效果——兼容当前各种主流浏览器[xyytIT]
  8. 【校招面试 之 剑指offer】第16题 数值的整数次方
  9. 两数之和-数据结构设计 &#183; Two Sum - Data structure design
  10. Win10 激活