CF1196C.Robot Breakout

普及/提高-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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

  1. the first action allows it to move from (xcx_c, ycy_c) to (xc−1x_c - 1, ycy_c);
  2. the second action allows it to move from (xcx_c, ycy_c) to (xcx_c, yc+1y_c + 1);
  3. the third action allows it to move from (xcx_c, ycy_c) to (xc+1x_c + 1, ycy_c);
  4. the fourth action allows it to move from (xcx_c, ycy_c) to (xcx_c, yc−1y_c - 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?

nn 个机器人从你的实验室逃跑了!你必须尽快找到它们,因为这些机器人尚处于实验阶段,其行为尚未经过测试,因此它们可能非常危险!

幸运的是,尽管机器人已经逃逸,你仍然对它们保有一定的控制能力。首先,你知晓每个机器人的当前位置:你所生活的世界可以建模为一个无限的坐标平面,第 ii 个机器人当前位于坐标为 (xi,yi)(x_i, y_i) 的点上。此外,你可以向所有机器人恰好发送一条命令。该命令需包含两个整数 XX 和 YY;当每个机器人接收到该命令后,便会开始朝向坐标为 (X,Y)(X, Y) 的点移动。机器人在以下两种情况下停止移动:

  • 要么它成功抵达 (X,Y)(X, Y);
  • 要么它无法再靠近 (X,Y)(X, Y)。

通常,所有机器人均应能从坐标平面上任意一点移动到任意另一点。每个机器人通常可通过四种动作进行移动。设机器人当前坐标为 (xc,yc)(x_c, y_c),则其移动系统允许它移动至以下四个相邻点之一:

  1. 第一种动作使其从 (xc,yc)(x_c, y_c) 移动至 (xc−1,yc)(x_c - 1, y_c);
  2. 第二种动作使其从 (xc,yc)(x_c, y_c) 移动至 (xc,yc+1)(x_c, y_c + 1);
  3. 第三种动作使其从 (xc,yc)(x_c, y_c) 移动至 (xc+1,yc)(x_c + 1, y_c);
  4. 第四种动作使其从 (xc,yc)(x_c, y_c) 移动至 (xc,yc−1)(x_c, y_c - 1)。

不幸的是,部分机器人的移动系统似乎出现了故障。对于每个机器人,你已知它能够执行哪些动作、不能执行哪些动作。

你希望发送一条命令,使得所有机器人最终聚集于同一点。为此,你必须选择一对整数 XX 和 YY,使得每个机器人都能到达点 (X,Y)(X, Y)。是否存在这样的点?

输入格式

The first line contains one integer qq (1≤q≤1051 \le q \le 10^5) — the number of queries.

Then qq queries follow. Each query begins with one line containing one integer nn (1≤n≤1051 \le n \le 10^5) — 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 xix_i, yiy_i, fi,1f_{i, 1}, fi,2f_{i, 2}, fi,3f_{i, 3} and fi,4f_{i, 4} (−105≤xi,yi≤105-10^5 \le x_i, y_i \le 10^5, 0≤fi,j≤10 \le f_{i, j} \le 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=1f_{i, j} = 1 if the ii-th robot can use the jj-th action, and fi,j=0f_{i, 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 10510^5.

第一行包含一个整数 qq(1≤q≤1051 \le q \le 10^5)—— 表示查询次数。

接下来是 qq 个查询。每个查询以一行开始,该行包含一个整数 nn(1≤n≤1051 \le n \le 10^5)—— 表示该查询中机器人的数量。随后是 nn 行,其中第 ii 行描述当前查询中的第 ii 个机器人:该行包含六个整数 xix_i、yiy_i、fi,1f_{i, 1}、fi,2f_{i, 2}、fi,3f_{i, 3} 和 fi,4f_{i, 4}(−105≤xi,yi≤105-10^5 \le x_i, y_i \le 10^5,0≤fi,j≤10 \le f_{i, j} \le 1)。前两个数表示第 ii 个机器人的初始位置;后四个数表示该机器人可使用的移动操作(若 fi,j=1f_{i, j} = 1,则第 ii 个机器人可以使用第 jj 种操作;若 fi,j=0f_{i, j} = 0,则不能使用第 jj 种操作)。

保证所有查询中机器人的总数不超过 10510^5。

输出格式

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: 11 XX YY, where XX and YY are the coordinates of the point reachable by all nn robots. Both XX and YY should not exceed 10510^5 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 10510^5 by absolute value.

你需要独立地回答每个查询,按照输入中查询出现的顺序依次作答。

要回答一个查询,你需要执行以下操作之一:

  • 如果不存在一个能被所有 nn 个机器人到达的点,则在单独一行输出数字 00;
  • 如果存在一个能被所有 nn 个机器人到达的点,则在同一行输出三个以空格分隔的整数:11 XX YY,其中 XX 和 YY 是这样一个所有机器人均可到达的点的坐标。XX 和 YY 的绝对值均不应超过 10510^5;题目保证:若至少存在一个所有机器人均可到达的点,则其中至少有一个点的两个坐标绝对值均不超过 10510^5。

输入输出样例

  • 输入#1

    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

    输出#1

    1 -1 -2
    1 2 5
    0
    1 -100000 -100000

输入解题思路,AI测评打分。不知道怎么写?

首页