Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <set>
- #include <string>
- #include <algorithm>
- using namespace std;
- using ll = long long;
- void cv(vector <int> v){
- for (auto x: v) cout<<x<<' ';
- cout<<'\n';
- }
- struct sct{
- int l,r;
- };
- int st1=-100, st2=-100;
- sct a;
- sct b;
- sct la;//limit
- sct lb;
- sct ra, rb; //res
- int l1,d1,r1,l2,d2,r2;
- int limL1, limR1, limL2, limR2;
- void csc(sct &x, string s){
- cout<<s<<'\n';
- cout<<x.l<<' '<<x.r<<' ';
- cout<<"\n\n";
- }
- bool inter(sct x, sct y){
- bool A = x.r > y.l && x.l < y.r;
- bool B = y.r > x.l && y.l < x.r;
- return A || B;
- }
- /*
- bool gd(){
- bool r = limit() && !inter();
- cout<<"gd r = "<<r<<"\n";
- return r;
- }*/
- /*
- var 1:
- <-a
- b->
- var 2:
- a->
- <-b
- */
- void get(int var, int shf){
- if (var == 0){
- //cout<<"CAN'T SOLVE _ BAD\n";
- st1=-1;
- st2=-1;
- }
- else if (var == 1){
- //cout <<"SOLVE VAR 1\n";
- if (abs(la.l - a.l) >= shf){
- // cout<<"ONE\n";
- st1 = a.l - shf;
- st2 = b.l;
- }else if (abs (lb.r - b.r) >= shf){
- //cout<<"TWO\n";
- st1 = a.l;
- st2 = b.l + shf;
- }
- else{
- // cout<<"THREE\n";
- st1 = la.l;
- st2 = b.l + shf - abs(a.l - la.l);
- }
- }
- else{
- //cout <<"SOLVE VAR 2\n";
- if ( (abs(la.r - a.r) >= shf)) {
- // cout<<"ONE\n";
- st1 = a.l + shf;
- st2 = b.l;
- }
- else if (abs(lb.l - b.l) >= shf){
- // cout<<"TWO\n";
- st1 = a.l;
- st2 = b.l - shf;
- }else{
- //cout<<"THREE\n";
- st1 = la.l;
- st2 = b.l - (shf - ( abs(la.l - a.l) ) );
- }
- }
- }
- void slv(){
- int shf;//need tot shift
- int cn;//can shift
- //var 1
- cn = abs(la.l - a.l) + abs(lb.r - b.r);
- shf = a.r - b.l;
- /* cout<<"check var 1\n";
- cout<<"shf= "<<shf<<"\n";
- cout<<"cn= "<<cn<<"\n";*/
- if (cn >= shf){
- get(1, shf);
- }
- else {
- /* cout<<"var 1 bad\n";
- cout<<"check var 2\n";*/
- shf = b.r - a.l;
- cn = abs(b.l - lb.l) + abs(a.r - la.r);
- /*cout<<"shf= "<<shf<<"\n";
- cout<<"cn= "<<cn<<"\n";*/
- if (cn >= shf) get(2, shf);
- else {
- // cout<<"all var bad - CANNOT\n";
- get(0, shf);
- }
- }
- }
- int main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- int n;
- cin>>n;
- for (int i =0;i<n;++i){
- cin>>limL1>>limR1>>limL2>>limR2;
- la = {limL1, limR1};
- lb = {limL2, limR2};
- cin>>l1>>d1>>l2>>d2;
- r1 = l1 + d1;
- r2 = l2 + d2;
- a = {l1, r1};
- b = {l2, r2};
- /*csc(a,"a");
- csc(b,"b");
- csc(la,"la");
- csc(lb, "lb");*/
- if (!inter(a, b)){
- cout<<a.l<<' '<<b.l<<'\n';
- continue;
- }
- slv();
- cout<<st1<<' '<<st2<<'\n';
- }
- }
- /*
- 1
- 14 22 12 18
- 15 5 16 2
- OK
- 1
- 12 22 14 20
- 14 5 15 4
- OK
- 1
- 12 14 16 18
- 12 2 16 2
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement