Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.00 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. pair<int, int> f1(int l1, int l2, int r1, int r2, int s1, int s2, int d1, int d2){
  5.     if (s1+d1 < s2){
  6.         return {s1, s2};
  7.     }
  8.     else if (l1 + d1 >= r2-d2){
  9.         return {-1, -1};
  10.     }
  11.     else{
  12.         if (s1 + d1 > s2)
  13.             s1 = s2-d1;
  14.         s1 = max(l1, s1);
  15.         if (s1+d1 > s2){
  16.             s2 = s1+d1;
  17.             s2 = min(s2, r2);
  18.         }
  19.         if (s1+d1 <= s2){
  20.             return {s1, s2};
  21.         }
  22.         else return {-1, -1};
  23.     }
  24. }
  25.  
  26. pair<int, int> f2(int l1, int l2, int r1, int r2, int s1, int s2, int d1, int d2){
  27.     if (s1+d1 < s2){
  28.         return {s1, s2};
  29.     }
  30.     else if (l2+d2 >= r1-d1){
  31.         return {-1, -1};
  32.     }
  33.     else{
  34.         if (s2 + d2 > s1)
  35.             s2 = s1 - d2;
  36.         s2 = max(l2, s2);
  37.         if (s2+d2 > s1){
  38.             s1 = s2+d2;
  39.             s1 = min(s1, r1);
  40.         }
  41.         if (s2+d2 <= s1){
  42.             return {s1, s2};
  43.         }
  44.         else return {-1, -1};
  45.     }
  46. }
  47. int main() {
  48.     iostream::sync_with_stdio(false); cout.tie(0); cin.tie(0);
  49.     int q; cin >> q;
  50.     while(q--){
  51.         int l1, l2, r1, r2;
  52.         cin >> l1 >> r1 >> l2 >> r2;
  53.         int s1, s2, d1, d2;
  54.         cin >> s1 >> d1 >> s2 >> d2;
  55.         pair<int, int> p1 = f1(l1, l2, r1, r2, s1, s2, d1, d2), p2 = f2(l1,l2,  r1, r2, s1, s2, d1, d2);
  56.         if (p1.first == -1 && p2.first == -1) cout << -1 << ' ' << -1 << '\n';
  57.         else{
  58.             if (p1.first == -1){
  59.                 cout << p2.first << ' ' << p2.second << '\n';
  60.             }
  61.             else if (p2.first == -1){
  62.                 cout << p1.first << ' ' << p1.second << '\n';
  63.             }
  64.             else{
  65.                 if (abs(s1 - p1.first) + abs(s2 - p1.second) < abs(s1-p2.first) + abs(s2-p2.second)){
  66.                     cout << p1.first << ' ' << p1.second << '\n';
  67.                 }
  68.                 else cout << p2.first << ' ' << p2.second << '\n';
  69.             }
  70.         }
  71.     }
  72.     return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement