UVA 618-doing Windows (number theory)

Source: Internet
Author: User
Tags cas gcd

Topic Link: 618-doing Windows Test Instructions: Given a size can not change the screen, and four size of the window, the change to maintain the aspect ratio, ask these four windows can adjust after all put down just fill the screen, can not overlap ideas: there are a few things: 4 stacked together, 3 stacks together + one , 2 and 2, one and two stacked together in one, these cases are all judged, the process of judging the use of GCD,LCM can seek the edge length. Code:
#include <stdio.h> #include <string.h>long long gcd (long long A, long long B) {if (b = = 0) return A; return gcd (b, a% b);} Long long LCM (long long A, long long B) {return A/GCD (A, b) * b;}    struct Win {Long long x, y;  BOOL Scanf_ () {scanf ("%lld%lld", &x, &y); if (x = = 0 | | y = = 0) return false;long long T = gcd (x, y); x/= t; y    /= T;return true;    } void Swap () {long Long t = x; x = y; y = t;    }} win, W[4];bool Check1 (Win A, win B, Win C, win D) {long long sum = 0;    if (win.y% a.y) return false;    Sum + = Win.y/a.y * A.X;    if (win.y% b.y) return false;    Sum + = Win.y/b.y * b.x;    if (win.y% c.y) return false;    Sum + = Win.y/c.y * c.x;    if (win.y% d.y) return false;    Sum + = Win.y/d.y * d.x;    if (sum! = win.x) return false; return true;}    BOOL Check (Win A, win B, Win C, long long wx, long long WY) {if (WY <= wx/a.x * a.y) return false;    Long Long yy = wy-wx/a.x * A.Y;    A long long sum = 0; if (yY% b.y) return false;    Sum + = Yy/b.y * b.x;    if (yy% c.y) return false;    Sum + = Yy/c.y * c.x;    if (sum! = WX) return false; return true;}      BOOL Judge3 (Win A, win B, Win C, long long wx, long long WY) {if (check (a, B, C, WX, WY) | | Check (b, A, C, WX, WY) ||    Check (c, a, B, WX, WY)) return true; return false;}    BOOL Judge2 (Win A, win B, Win C, long long wx, long long WY) {if (Judge3 (A, B, C, WX, WY)) return true;     A.swap ();     B.swap ();    C.swap ();    if (Judge3 (A, B, C, WY, WX)) return true; return false;}    BOOL Check2 (Win A, win B, Win C, win D) {long long sum = 0;    if (win.x% d.x) return false;    Long Long WY = win.x/d.x * D.Y;    if (WY >= WIN.Y) return false;    Long Long yy = Win.y-wy;    if (Judge2 (A, B, C, win.x, yy)) return true;    if (yy% a.y) return false;    Sum + = Yy/a.y * A.X;    if (yy% b.y) return false;    Sum + = Yy/b.y * b.x;    if (yy% c.y) return false;    Sum + = Yy/c.y * c.x;    int flag = 0; if (sum = = WIN.X) flag = 1; return flag;}    BOOL Check3 (Win A, win B, Win C, win D) {long long sum = 0;    Long Long WY = LCM (A.Y, B.Y);    if (WY >= WIN.Y) return false;    Sum + = Wy/a.y * A.X;    Sum + = Wy/b.y * b.x;    if (win.x% sum) return false;    if (WIN.Y <= win.x/sum * WY) return false;    Long Long yy = win.y-win.x/sum * WY;    sum = 0;    if (yy% c.y) return false;    Sum + = Yy/c.y * c.x;    if (yy% d.y) return false;    Sum + = Yy/d.y * d.x;    if (win.x! = sum) return false; return true;}    BOOL Judge () {if (Check1 (w[0], w[1], w[2], w[3])) return true; if (Check2 (w[0], w[1], w[2], w[3]) | | Check2 (w[0], w[1], w[3], w[2]) | | Check2 (w[0], w[3], w[2], w[1]) | | Check2 (    W[3], w[1], w[2], w[0]) return true;     if (Check3 (w[0], w[1], w[2], w[3]) | | check3 (w[0], w[2], w[1], w[3]) | | check3 (w[0], w[3], w[1], w[2]) return true; return false;}    BOOL Solve () {if (judge ()) return true;     Win.swap (); For (long long i = 0; i < 4;    i++) W[i].swap ();    if (judge ()) return true; return false;}    int main () {long long cas = 0; while (~SCANF ("%lld%lld", &win.x, &AMP;WIN.Y) && win.x | | win.y) {for (long long i = 0; i < 4; i++) W[i] . Scanf_ ();p rintf ("Set%lld:%s\n", ++cas, Solve ()?    "Yes": "No"); } return 0;}



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.