Codeforces Round #575 div.3 C

  • 题目大意: 给出一些机器人,能够上下左右移动,但有些机器人会被限制其中的一些操作,求经过任意的移动机器人能否相遇,如果相遇输出相遇位置
  • 思路: 抽象成(x,y)轴上的移动,每个机器人只能在可行区间移动,并要重新更新可行区间.

#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;
}

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

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

原文地址:https://www.cnblogs.com/xxrlz/p/11242046.html