Friday 28 July 2017

Lightoj 1077 - How Many Points?

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long int
  4.  
  5. ll gcd(ll a, ll b){
  6.     //if(a<b) swap(a, b);
  7.     while(a){
  8.         ll temp = a;
  9.         a = b%a;
  10.         b = temp;
  11.         //cout<<"temp a b"<<temp<<"  "<<a<<"  "<<b<<"  ";
  12.     }
  13.     return b;
  14. }
  15. /*
  16.  
  17. ll gcd(ll b,ll a){
  18.   ll tmp;
  19.   while(b){
  20.     tmp = b;
  21.     b = a%b;
  22.     a = tmp;
  23.     cout<<"temp a b"<<tmp<<"  "<<a<<"  "<<b<<"  ";
  24.   }
  25.   return a;
  26. }
  27. */
  28. int main(){
  29.     int ts;
  30.     //cdcout<<gcd(10, 15);
  31.     cin>>ts;
  32.     for(int i = 1; i <= ts; i++){
  33.     ll x1, y1, x2, y2;
  34.     scanf("%lld%lld%lld%lld"&x1, &y1, &x2, &y2);
  35.     ll ans;
  36.     ll dx = abs(x1-x2);
  37.     ll dy = abs(y1-y2);
  38.     if(dx == 0) ans = dy+1;
  39.     else if(dy == 0) ans = dx+1;
  40.     else ans = gcd(dx, dy)+1;
  41.     printf("Case %d: %lld\n", i, ans);
  42.     }
  43.  
  44.     return 0;
  45.    
  46. }

No comments:

Post a Comment

Most Featured Post

Lightoj 1159 - Batman

http://lightoj.com/volume_showproblem.php?problem=1159 problem analysis: First i thought of this as if s1, s2 and s3 are those three str...