Advertisement
Plabon_dutta

Codeforces Round #731 (Div. 3), problem: (A) Shortest Path with Obstacle

Jul 10th, 2021
861
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <algorithm>
  3. #include <math.h>
  4. #include<string>
  5. #include<vector>
  6.  
  7. #define pi acos(-1.0)
  8. #define ll long long int
  9. #define sc scanf
  10. #define pf printf
  11. #define fin for(ll i=0; i<n; i++)
  12. #define fjm for(ll j=0; j<m; j++)
  13. #define fr(i,a,n) for(ll i=a; i<n; i++)
  14. #define rf(i,n,a) for(ll i=n-1; i>=a; i--)
  15. #define readfirst() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
  16.  
  17. using namespace std;
  18.  
  19. ll gcd(ll p, ll q) {
  20.     return q==0?p:gcd(q,p%q);
  21. }
  22.  
  23. int main() {
  24.     readfirst();
  25.     ll t, x1, x2, x3, y1, y2, y3;
  26.     cin >> t;
  27.     while(t--) {
  28.         cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
  29.         ll x, y, a, b, c, d, s=0;
  30.         s=abs(x1-x2)+abs(y1-y2);
  31.         if(x1==x3 && x2==x3) {
  32.             a=min(y1,y2);
  33.             b=max(y1,y2);
  34.             if(y3>a && y3<b) s+=2;
  35.         }
  36.         else if(y1==y3 && y2==y3) {
  37.             c=min(x1,x2);
  38.             d=max(x1,x2);
  39.             if(x3>c && x3<d) s+=2;
  40.         }
  41.         cout << s << "\n";
  42.     }
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement