UVA - 1435 Business Cards (數論)

來源:互聯網
上載者:User

標籤:des   style   http   os   io   for   ar   div   amp   

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 (數論)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.