SGU 106 the equation

Source: Internet
Author: User

Sub-situation Discussion

Expand Euclid

The code is changed according to other people's ideas.

1 /*Author:usedrose*/2 /*Created TIME:2015/7/25 14:51:42*/3 /*File name:2.cpp*/4#include <cstdio>5#include <iostream>6#include <algorithm>7#include <sstream>8#include <cstdlib>9#include <cstring>Ten#include <climits> One#include <vector> A#include <string> -#include <ctime> -#include <cmath> the#include <deque> -#include <queue> -#include <stack> -#include <Set> +#include <map> - #defineINF 0x3f3f3f3f + #defineEPS 1e-8 A #definePi ACOs (-1.0) at #defineMAXN 1110 - #defineOK cout << "OK" << Endl; - #defineO (a) cout << #a << "=" << a << Endl - #defineO1 (A, b) cout << #a << "=" << a << "<< #b <<" = "<< b << Endl - using namespacestd; -typedefLong LongLL; in  - voidEXGCD (ll A, ll B, LL &d, LL &x, LL &y) to { +     if(!b) d = A, x =1, y =0; -     Else { theEXGCD (b, a%B, D, y, x); *Y-= x* (A/b); $     }Panax Notoginseng } -  the intMain () + { A     //freopen ("data.in", "R", stdin); the     //freopen ("Data.out", "w", stdout); +Cin.tie (0); -Ios::sync_with_stdio (false); $ LL A, B, C, D, X, Y, x1, x2, y1, y2; $      while(Cin >> a >> b >>c) { -CIN >> x1 >> x2 >> y1 >>Y2; -         if(A = =0|| b = =0) { the             if(A = =0&&b) { -                 if(c%b | | c/b > Y2 | | c/b < y1) cout <<"0"<<Endl;Wuyi                 Elsecout << x2-x1 +1<<Endl; the             } -             Else if(b = =0&&a) { Wu                 if(c%a | | c/a > X1 | | c/b < x1) cout <<"0"<<Endl; -                 Elsecout << Y2-y1 +1<<Endl; About             }  $             Else { -                 if(c) cout <<"0"<<Endl; -                    Elsecout << (x2-x1 +1) * (Y2-y1 +1) <<Endl;  -             } A         } +         Else { the             if(C <0) C =-C; -             ElseA =-A, B =-b; $             if(A <0) { theA =-A; theX1 =-X1; thex2 =-x2; the swap (x1, x2); -             } in             if(b <0) { theb =-b; theY1 =-Y1; Abouty2 =-Y2; the swap (y1, y2); the             } the             if(A <b) EXGCD (b, A, D, y, x); +             ElseEXGCD (A, B, D, X, y); -             if(c%d) { thecout <<"0"<<Endl;Bayi                 Continue; the             } theA/= D, b/= D, c/=D; -             //Small Optimization -              while(x < x1) x + = b, y-=A; the              while(x > x2) x-= b, y + =A; theLL ans =0; the             BOOL inch=false; thex *= C, y *=C; -              while(x <=x2) { the                 if(x >= x1 && x <= x2 && y >= y1 && y <=y2) { the                     inch=true; the                      Break;94                 }     theX + = b, y-=A; the             } the              while(!inch&& x >=x1) {98                 if(x >= x1 && x <= x2 && y >= y1 && y <=y2) {  About                     inch=true; -                      Break;101                 }    102X-= b, y + =A;103             } 104             if(inch) { theAns + = min ((x2-x)/b, (Y-Y1)/a);106Ans + = min ((x-x1)/b, (y2-y)/a);107             }108cout << ans +inch<<Endl;109         } the     }111     return 0; the}
View Code

SGU 106 the equation

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.