UVA - 1435 Business Cards (数论)

本文介绍了一种解决如何将特定尺寸的大纸张裁剪成多个小规格名片的问题,并提供了具体的编程实现方法。通过数学分析与编程技巧,确保了纸张利用率最大化。

Description

Download as PDF

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.

\epsfbox{p4384.eps}

Input

The input contains several test cases. The first line contains the number of test cases t (t$ \le$105). Then t test cases follow. Each of them consists of one line containing four integers a, b, c, d (1$ \le$a, b, c, d$ \le$109). 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
题意:给你a,b,c,d四个数,问你能把c*d的矩阵分成若干个a*b的矩阵
思路:分情况讨论:1全都竖着放;2全都横着放,3交错放,注意第3种情况只能是长或者是宽是组合的,等于说就是求解ax+by=c|d的这两种情况,这个可以试着画一下。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
typedef long long ll;
using namespace std;

int find(ll a, ll b, ll c) {
	if (a < b)	
		swap(a, b);
	for (ll i = a; i < c; i += a)
		if ((c - i) % b == 0)
			return 1;
	return 0;
}

int main() {
	ll a, b, c, d;
	int t;
	scanf("%d", &t);
	while (t--) {
		scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
		if ((c % a == 0 && d % b == 0) || (d % a == 0 && c % b == 0))
			printf("YES\n");
		else if (c % a == 0 && c % b == 0 && find(a, b, d))
			printf("YES\n");
		else if (d % a == 0 && d % b == 0 && find(a, b, c))
			printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值