其他分享
首页 > 其他分享> > Codeforces Round #575 div.3 C

Codeforces Round #575 div.3 C

作者:互联网


#include<bits/stdc++.h>
#define ll long long 
#define FOR(i,n) for(int i =1; i <= n;++i ) 
#define FOR0(i,n) for(int i =0; i < n;++i )  
#define inf 100000
#define EPS (1e-9)
using namespace std; 
const int maxn = 2*1e5+10;
struct rob{
    int x,y;
    int op[5];
};
vector<rob> rbs;
pair<int,int> neetPos;
pair<int,int> xline;
pair<int,int> yline;
rob crob;

int check(){
    for(auto rb:rbs){
        if(rb.x<xline.second && !rb.op[3])  return false;
        if(rb.x>xline.first && !rb.op[1])   return false;
        if(!rb.op[1]){
            xline.second = max(rb.x,xline.second);
        }
        if(!rb.op[3]){
            xline.first = min(rb.x,xline.first);
        }
        if(xline.first < xline.second)  return false;
    }   
    for(auto rb:rbs){
        if(rb.y<yline.second && !rb.op[2])  return false;
        if(rb.y>yline.first && !rb.op[4])   return false;
        if(!rb.op[2]){
            yline.first = min(rb.y,yline.first);
        }
        if(!rb.op[4]){
            yline.second = max(rb.y,yline.second);
        }
        if(yline.first < yline.second)  return false;
    }
    return true;
}
int n;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t,val;
    cin >> t;
    while(t--){
        rbs.clear();
        int sign = 0;
        neetPos = {-inf,-inf};
        xline = {inf,-inf};
        yline = {inf,-inf};
        cin >> n;
        FOR(i,n){
            cin >>crob.x >> crob.y;
            FOR(j,4){
                cin >> val;
                crob.op[j] = val;
                crob.op[0] += val;
            }
            // if(crob.op[0]==4)    continue;
            // if(crob.op[0]==0){
            //  if(xline.first==inf){
            //      xline.first = xline.second= crob.x;
            //      yline.second = yline.first= crob.y;
            //  }else{
            //      if(xline.first!=crob.x || yline.first!=crob.y){
            //          sign = 1;
            //          break;
            //      }
            //  }
            //  continue;
            // }
            rbs.push_back(crob);
        }
        // if(sign){
        //  cout << 0 << endl;
        //  continue;
        // }
        if(check()){
            // if(xline.first ==inf)    xline.first = crob.x;
            // if(yline.first ==inf)    yline.first = crob.y;
            cout << 1 <<' ' << xline.first << ' ' << yline.first << endl;
        }else{
            cout << 0 << endl;
        }
    }
    return 0;
}

这道题被卡了很久,最后也没做出来,一开始在想先求出相遇点,再根据相遇点判断的做法

且初始边界应该为题目中所给的取值范围,因为有可能边界不被更新就判断完了

标签:xline,Codeforces,575,yline,rb,div.3,op,crob,first
来源: https://www.cnblogs.com/xxrlz/p/11242046.html