乐逍遥xwl

导航

Codeforces Round #575 (Div. 3) C - Robot Breakout

Codeforces Round #575 (Div. 3)

 

C - Robot Breakout

n robots have escaped from your laboratory! You have to find them as soon as possible, because these robots are experimental, and their behavior is not tested yet, so they may be really dangerous!

Fortunately, even though your robots have escaped, you still have some control over them. First of all, you know the location of each robot: the world you live in can be modeled as an infinite coordinate plane, and the i-th robot is currently located at the point having coordinates (xi, yi). Furthermore, you may send exactly one command to all of the robots. The command should contain two integer numbers X and Y, and when each robot receives this command, it starts moving towards the point having coordinates (X, Y). The robot stops its movement in two cases:

  • either it reaches (X, Y);
  • or it cannot get any closer to (X, Y).

Normally, all robots should be able to get from any point of the coordinate plane to any other point. Each robot usually can perform four actions to move. Let's denote the current coordinates of the robot as (xc, yc). Then the movement system allows it to move to any of the four adjacent points:

  1. the first action allows it to move from (xc, yc) to (xc−1, yc);
  2. the second action allows it to move from (xc, yc) to (xc, yc+1);
  3. the third action allows it to move from (xc, yc) to (xc+1, yc);
  4. the fourth action allows it to move from (xc, yc) to (xc, yc−1).

Unfortunately, it seems that some movement systems of some robots are malfunctioning. For each robot you know which actions it can perform, and which it cannot perform.

You want to send a command so all robots gather at the same point. To do so, you have to choose a pair of integer numbers X and Y so that each robot can reach the point (X, Y). Is it possible to find such a point?

Input

The first line contains one integer q (1≤q≤105) — the number of queries.

Then q queries follow. Each query begins with one line containing one integer n (1≤n≤105) — the number of robots in the query. Then n lines follow, the i-th of these lines describes the i-th robot in the current query: it contains six integer numbers xi, yi, fi,1, fi,2, fi,3 and fi,4 (−105≤xi,yi≤105, 0≤fi,j≤1). The first two numbers describe the initial location of the i-th robot, and the following four numbers describe which actions the i-th robot can use to move (fi,j=1 if the i-th robot can use the j-th action, and fi,j=0 if it cannot use the j-th action).

It is guaranteed that the total number of robots over all queries does not exceed 105.

Output

You should answer each query independently, in the order these queries appear in the input.

To answer a query, you should do one of the following:

  • if it is impossible to find a point that is reachable by all n robots, print one number 0 on a separate line;
  • if it is possible to find a point that is reachable by all n robots, print three space-separated integers on the same line: 1 X Y, where Xand Y are the coordinates of the point reachable by all n robots. Both X and Y should not exceed 105 by absolute value; it is guaranteed that if there exists at least one point reachable by all robots, then at least one of such points has both coordinates not exceeding 105 by absolute value.

Example

input

4

2

-1 -2 0 0 0 0

-1 -2 0 0 0 0

3

1 5 1 1 1 1

2 5 0 1 0 1

3 5 1 0 0 0

2

1337 1337 0 1 1 1

1336 1337 1 1 0 1

1

3 5 1 1 1 1

output

1 -1 -2

1 2 5

0

1 -100000 -100000

 

题意:题目给出n个机器人的位置以及这个机器人的四个能否上下左右的标记,

问你在边界绝对值不超过 10^5 的地图内,能否找到一个点,使所有机器人都能到达该点。

思路:根据这些机器人不能走的方位维护一个所有机器人都能走的可行区间,

最后看区间是否成立,成立输出 1 和 区间上任意一点,不行输出 0 就行了。

另外,这里区间就是左下点和右上点组成的矩阵。

 

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<cstring>
 5 #include<map>
 6 #include<set>
 7 #include<vector>
 8 #include<queue>
 9 #include<algorithm>
10 using namespace std;
11 #define ll long long 
12 const int inf=1e9+7;
13 const int mod=1e9+7;
14  
15 const int maxn=1e5+5;
16 pair<int,int> num[maxn];
17  
18 int main()
19 {
20     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
21     
22     int T;
23     cin>>T;
24     int n;
25     
26     while(T--)
27     {
28         cin>>n;
29         
30         pair<int,int> left={-100000,-100000};//左下点 
31         pair<int,int> right={100000,100000};//右上点 
32         int a,b,c,d;//左上右下不能走 
33         for(int i=0;i<n;i++)
34         {
35             cin>>num[i].first>>num[i].second>>a>>b>>c>>d;
36             
37             if(a==0)
38                 left.first=max(left.first,num[i].first);
39             if(b==0)
40                 right.second=min(right.second,num[i].second);
41             if(c==0)
42                 right.first=min(right.first,num[i].first);
43             if(d==0)
44                 left.second=max(left.second,num[i].second);
45         }
46         
47         if(left.first>right.first||left.second>right.second)//不成立 
48         {
49             cout<<0<<endl;
50             continue;
51         }
52         
53         cout<<1<<" "<<left.first<<" "<<left.second<<endl;
54     }
55     
56     return 0;
57 }

 

posted on 2019-07-30 18:18  乐逍遥xwl  阅读(136)  评论(0编辑  收藏  举报