codeforces.com/contest/1196/problem/C

C. Robot Breakout
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

nn 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 ii-th robot is currently located at the point having coordinates (xixi, yiyi). Furthermore, you may send exactly one command to all of the robots. The command should contain two integer numbers XX and YY, and when each robot receives this command, it starts moving towards the point having coordinates (XX, YY). The robot stops its movement in two cases:

  • either it reaches (XX, YY);
  • or it cannot get any closer to (XX, YY).

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 (xcxc, ycyc). Then the movement system allows it to move to any of the four adjacent points:

  1. the first action allows it to move from (xcxc, ycyc) to (xc1xc−1, ycyc);
  2. the second action allows it to move from (xcxc, ycyc) to (xcxc, yc+1yc+1);
  3. the third action allows it to move from (xcxc, ycyc) to (xc+1xc+1, ycyc);
  4. the fourth action allows it to move from (xcxc, ycyc) to (xcxc, yc1yc−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 XX and YY so that each robot can reach the point (XX, YY). Is it possible to find such a point?

Input

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

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

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

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 nn robots, print one number 00 on a separate line;
  • if it is possible to find a point that is reachable by all nn robots, print three space-separated integers on the same line: 1XYY, where XXand YY are the coordinates of the point reachable by all nn robots. Both XX and YY should not exceed 105105 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 105105 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个机器人和4个方向,1表示可以移动,0表示不能移动,对于每行数据,前两个表示机器人位置,后4个表示移动情况

         问是否存在一个所有机器人都可以到达的位置,如果不存在输出0,否则输出1,并输出可以移动到的位置

思路:一开始将可到达的位置放到极限点,每输入一个数据,就对这个点进行更新

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAX 200005
int main()
{
    int c;scanf("%d",&c);
    while(c--)
    {
        int n,x1=-1e5,y1=1e5,x2=1e5,y2=-1e5,a,b,c,d,ax,ay;
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%d %d %d %d %d %d",&ax,&ay,&a,&b,&c,&d);
            if(!a) x1=max(x1,ax);//不能左移
            if(!b) y1=min(y1,ay);//不能上移
            if(!c) x2=min(x2,ax);//不能右移
            if(!d) y2=max(y2,ay);//不能下移
        }
        if(x1>x2||y1<y2)
            cout<<0<<endl;
        else
        {
            cout<<1<<' ';
            cout<<x1<<' '<<y2<<endl;//对于不能右移的,x2小一点依旧可以成立
        }                           //对于不能上移的,y1小一点依旧可以成立
    }
    return 0;
}

 

 

转载于:https://www.cnblogs.com/1911087165zzx/p/11242578.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值