UVA - 1435 Business Cards (数论)
来源:互联网 发布:淘宝网宝贝详情模板 编辑:程序博客网 时间:2024/06/05 17:54
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 casest (t105). Thent test cases follow. Each of them consists of one line containing four integersa, b, c, d (1a,b, c, d109). Numbersa 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 62 3 8 62 3 6 82 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;}
- UVA - 1435 Business Cards (数论)
- UVa 10940 - Throwing cards away II(数论,规律)
- BNUOJ 1095 Business Cards
- hdu 2965Business Cards
- LA4384 Business Cards
- UVALive 4384 Business Cards
- UVA 10110(数论)
- UVA 138(数论)
- !codeforces 399C Cards-数论&贪心-(暴力枚举)
- CodeForces 399C Cards (数论)
- uva 1388 - Graveyard(数论)
- uva 11889 - Benefit(数论)
- UVA 11889 - Benefit(数论)
- UVA 10139 Factovisors(数论)
- UVa 11889 - Benefit (数论)
- uva 1388 - Graveyard(数论)
- uva-12484-cards
- UVA 11421 - Arranging Cards
- 第一个chrome应用
- 使用Tcl脚本分配FPGA管脚
- 到底选择合成还是继承
- 大学一年之后的总结
- switch case 语句特征
- UVA - 1435 Business Cards (数论)
- Markdown中插入数学公式的方法
- linux登录方式的设置
- linux nohup命令详解
- python 字典排序<转>
- servlet路径映射优先顺序
- 001-练习01:linux_命令使用40道例子
- hdu 1873 看病要排队
- npm install 解决报错