Korotkodul

Innoplis

Dec 9th, 2021 (edited)
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <set>
  5. #include <string>
  6. #include <algorithm>
  7. using namespace std;
  8. using ll = long long;
  9. void cv(vector <int> v){
  10. for (auto x: v) cout<<x<<' ';
  11. cout<<'\n';
  12. }
  13.  
  14. struct sct{
  15. int l,r;
  16. };
  17.  
  18.  
  19.  
  20.  
  21. int st1=-100, st2=-100;
  22.  
  23. sct a;
  24. sct b;
  25. sct la;//limit
  26. sct lb;
  27. sct ra, rb; //res
  28. int l1,d1,r1,l2,d2,r2;
  29. int limL1, limR1, limL2, limR2;
  30.  
  31. void csc(sct &x, string s){
  32. cout<<s<<'\n';
  33. cout<<x.l<<' '<<x.r<<' ';
  34. cout<<"\n\n";
  35. }
  36.  
  37. bool inter(sct x, sct y){
  38.  
  39. bool A = x.r > y.l && x.l < y.r;
  40. bool B = y.r > x.l && y.l < x.r;
  41. return A || B;
  42. }
  43.  
  44. /*
  45. bool gd(){
  46. bool r = limit() && !inter();
  47. cout<<"gd r = "<<r<<"\n";
  48. return r;
  49. }*/
  50. /*
  51. var 1:
  52. <-a
  53. b->
  54.  
  55. var 2:
  56. a->
  57. <-b
  58.  
  59. */
  60. void get(int var, int shf){
  61. if (var == 0){
  62. //cout<<"CAN'T SOLVE _ BAD\n";
  63. st1=-1;
  64. st2=-1;
  65. }
  66. else if (var == 1){
  67. //cout <<"SOLVE VAR 1\n";
  68. if (abs(la.l - a.l) >= shf){
  69. // cout<<"ONE\n";
  70. st1 = a.l - shf;
  71. st2 = b.l;
  72. }else if (abs (lb.r - b.r) >= shf){
  73. //cout<<"TWO\n";
  74. st1 = a.l;
  75. st2 = b.l + shf;
  76. }
  77. else{
  78. // cout<<"THREE\n";
  79. st1 = la.l;
  80. st2 = b.l + shf - abs(a.l - la.l);
  81. }
  82. }
  83. else{
  84. //cout <<"SOLVE VAR 2\n";
  85. if ( (abs(la.r - a.r) >= shf)) {
  86. // cout<<"ONE\n";
  87. st1 = a.l + shf;
  88. st2 = b.l;
  89. }
  90. else if (abs(lb.l - b.l) >= shf){
  91. // cout<<"TWO\n";
  92. st1 = a.l;
  93. st2 = b.l - shf;
  94. }else{
  95. //cout<<"THREE\n";
  96. st1 = la.l;
  97. st2 = b.l - (shf - ( abs(la.l - a.l) ) );
  98. }
  99. }
  100. }
  101.  
  102.  
  103.  
  104. void slv(){
  105.  
  106. int shf;//need tot shift
  107. int cn;//can shift
  108. //var 1
  109. cn = abs(la.l - a.l) + abs(lb.r - b.r);
  110. shf = a.r - b.l;
  111. /* cout<<"check var 1\n";
  112. cout<<"shf= "<<shf<<"\n";
  113. cout<<"cn= "<<cn<<"\n";*/
  114. if (cn >= shf){
  115. get(1, shf);
  116. }
  117. else {
  118. /* cout<<"var 1 bad\n";
  119. cout<<"check var 2\n";*/
  120. shf = b.r - a.l;
  121. cn = abs(b.l - lb.l) + abs(a.r - la.r);
  122. /*cout<<"shf= "<<shf<<"\n";
  123. cout<<"cn= "<<cn<<"\n";*/
  124. if (cn >= shf) get(2, shf);
  125. else {
  126. // cout<<"all var bad - CANNOT\n";
  127. get(0, shf);
  128. }
  129. }
  130. }
  131.  
  132. int main()
  133. {
  134. ios::sync_with_stdio(0);
  135. cin.tie(0);
  136. cout.tie(0);
  137.  
  138. int n;
  139. cin>>n;
  140. for (int i =0;i<n;++i){
  141. cin>>limL1>>limR1>>limL2>>limR2;
  142. la = {limL1, limR1};
  143. lb = {limL2, limR2};
  144. cin>>l1>>d1>>l2>>d2;
  145. r1 = l1 + d1;
  146. r2 = l2 + d2;
  147. a = {l1, r1};
  148. b = {l2, r2};
  149. /*csc(a,"a");
  150. csc(b,"b");
  151. csc(la,"la");
  152. csc(lb, "lb");*/
  153. if (!inter(a, b)){
  154. cout<<a.l<<' '<<b.l<<'\n';
  155. continue;
  156. }
  157. slv();
  158. cout<<st1<<' '<<st2<<'\n';
  159. }
  160.  
  161. }
  162.  
  163. /*
  164. 1
  165. 14 22 12 18
  166. 15 5 16 2
  167. OK
  168.  
  169. 1
  170. 12 22 14 20
  171. 14 5 15 4
  172. OK
  173.  
  174. 1
  175. 12 14 16 18
  176. 12 2 16 2
  177.  
  178. */
  179.  
Add Comment
Please, Sign In to add comment