UVA - 1435 Business Cards (数论)

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 (t105). Then
t test cases follow. Each of them consists of one line containing four integers
a, b,
c, d (1a,
b, c, d109). 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;
}

时间: 2024-07-28 13:48:42

UVA - 1435 Business Cards (数论)的相关文章

uva 10560 - Minimum Weight(数论)

题目连接:uva 10560 - Minimum Weight 题目大意:给出n,问说至少需要多少个不同重量的砝码才能称量1~n德重量,给出所选的砝码重量,并且给出k,表示有k个重量需要用上述所选的砝码测量. 解题思路:重量为1的砝码肯定要选,它可以表示到1的重量,那么下一个砝码的重量肯定选择3(2?1+1),这样1,3分别可以用一个砝码表示,而2,4分别为3-1和3+1,这样1~4的重量也都可以表示.于是有公式ai=si?1?2+1. #include <cstdio> #include &

uva 11105 - Semi-prime H-numbers(数论)

题目链接:uva 11105 - Semi-prime H-numbers 题目大意:H-number为4?k+1(k为非负数),H-composites为因子中含有H-number(不包括自己本身)的数,反之久是H-prime,给定n,求有多少H-composites. 解题思路:首先用筛选法求出范围内的H-prime,然后枚举两个判断乘积是否在范围内. #include <cstdio> #include <cstring> const int maxn = 1e6+5; ty

UVA 11754 - Code Feat(数论)

UVA 11754 - Code Feat 题目链接 题意:给定一个c个x, y1,y2,y3..yk形式,前s小的答案满足s % x在集合y1, y2, y3 ... yk中 思路:LRJ大白例题,分两种情况讨论 1.所有x之积较小时候,暴力枚举每个集合选哪个y,然后中国剩余定理求解 2.所有x之积较大时候,选定一个k/x尽可能小的序列,枚举x * t + y (t = 1, 2, 3...)去暴力求解. 代码: #include <stdio.h> #include <string.

UVA 718 - Skyscraper Floors(数论)

UVA 718 - Skyscraper Floors 题目链接 题意:在一个f层高的楼上,有e个电梯,每个电梯有x,y表示y + k * x层都可以到,现在要问从a层能否到达b层(中间怎么换乘电梯不限制) 思路:对于两个电梯间能不能换乘,只要满足y[i] + xx x[i] == y[j] + yy y[j].然后移项一下,就可以用拓展欧几里得求解,进而求出x,y的通解,然后利用通解范围x' >= 0, y' >= 0, x[i] x' + y[i] <= f, x[j] y' + y

UVA 10692 - Huge Mods(数论)

UVA 10692 - Huge Mods 题目链接 题意:求a0a1a2...mod m 思路:直接算肯定不行,利用欧拉定理ab=a(b mod phi(m) + phi(m))(b>=phi(m)),对指数进行降值处理,然后就可以利用快速幂去计算了,计算过程利用递归求解. 代码: #include <stdio.h> #include <string.h> const int N = 1005; int phi[N * 10], vis[N * 10], m, n, a[

uva 718 - Skyscraper Floors(数论+bfs)

题目链接:uva 718 - Skyscraper Floors 题目大意:一栋大楼,有F层楼,E个电梯,现在要从A层到B层,问是否可行,每个电梯给出Xi和Yi,代表这个电梯可以到达的层数Yi+k?Xi(k≥0) 解题思路:建图,以A,B以及电梯为节点建图,将可以到达A,B这两层的电梯与这两点建边,在将两两电梯可以达到同一层的建边,判断方法为:Yi+aXi=Yj+bXj,移项得:aXi+bXj=Yj?Yi,即是一个线性方程,用拓展欧几里得算法求出通解的形式,判断是否存在通解在0~F之间即可. #

UVA 10623 - Thinking Backward(数论)

UVA 10623 - Thinking Backward 题目链接 题意:给定一个数量,求用圆,椭圆,三角形分割平面,分割出该数量,输出所有情况 思路:有公式2 + 2m(m-1) + n(n-1) + 4mn + 3p(p-1) + 6mp + 6np 由于m和p都是[0,100],所以可以枚举m和p,去求出n,然后判断合不合适 代码: #include <stdio.h> #include <string.h> #include <math.h> #include

uva 11728 - Alternate Task(数论)

题目链接:uva 11728 - Alternate Task 题目大意:给出S,求N,要求N所有的因子和为S. 解题思路:枚举因子i,所有整除i的数和加上i. #include <cstdio> #include <cstring> const int N = 1005; int n, c[N], v[N]; void init () { memset(c, 0, sizeof(c)); memset(v, -1, sizeof(v)); for (int i = 1; i &l

UVA 10951 - Polynomial GCD(数论)

UVA 10951 - Polynomial GCD 题目链接 题意:给定两个多项式,求多项式的gcd,要求首项次数为1,多项式中的运算都%n,并且n为素数. 思路:和gcd基本一样,只不过传入的是两个多项式,由于有%n这个条件,所以计算过程可以用乘法逆去计算除法模,然后最后输出的时候每项除掉首项的次数就是答案了. 代码: #include <stdio.h> #include <string.h> #include <vector> using namespace s