C. Robot Breakout

time limit per test3 seconds

memory limit per test256 megabytes

inputstandard input

outputstandard output

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:

the first action allows it to move from (xc, yc) to (xc−1, yc);

the second action allows it to move from (xc, yc) to (xc, yc+1);

the third action allows it to move from (xc, yc) to (xc+1, yc);

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 X and 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

inputCopy

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

outputCopy

1 -1 -2

1 2 5

0

1 -100000 -100000

题意:

给你n个机器人的坐标,并且告诉你每一个机器人可以走的方向(只有4个方向),找你找出一个所有机器人都能到达的点。

思路:

维护四个值,最右的x,最左的x,最上的y,最下的y。刚开始定为最大值,构成一个全局矩阵。

根据机器人的坐标和可行方向来缩小能走到的范围,最后判断还能否构造矩阵,能就输出矩阵的任意一个数,否则输出0

本地比赛时写复杂了,多维护了很多无用的变量,并且上下左右没有根据x+-1来确定清楚,导致浪费时间,反思一下。

细节见代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define INF 0x3f3f3f3f
const int MAXC = 1e5; int main() {
int q;
cin >> q;
while (q--) {
int n;
cin >> n;
int mnx = -MAXC, mxx = MAXC;
int mny = -MAXC, mxy = MAXC;
while (n--) {
int x, y, f1, f2, f3, f4;
cin >> x >> y >> f1 >> f2 >> f3 >> f4;
if (!f1) mnx = max(mnx, x);
if (!f2) mxy = min(mxy, y);
if (!f3) mxx = min(mxx, x);
if (!f4) mny = max(mny, y);
}
if (mnx <= mxx && mny <= mxy)
cout << "1 " << mnx << " " << mny << "\n";
else
cout << "0\n";
} return 0;
}

Codeforces Round #575 (Div. 3) C. Robot Breakout (模拟,实现)的更多相关文章

  1. Codeforces Round #575 (Div. 3) 昨天的div3 补题

    Codeforces Round #575 (Div. 3) 这个div3打的太差了,心态都崩了. B. Odd Sum Segments B 题我就想了很久,这个题目我是找的奇数的个数,因为奇数想分 ...

  2. Codeforces Round #368 (Div. 2) B. Bakery (模拟)

    Bakery 题目链接: http://codeforces.com/contest/707/problem/B Description Masha wants to open her own bak ...

  3. Codeforces Round #575 (Div. 3)

    本蒟蒻已经掉到灰名了(菜到落泪),希望这次打完能重回绿名吧...... 这次赛中A了三题 下面是本蒟蒻的题解 A.Three Piles of Candies 这题没啥好说的,相加除2就完事了 #in ...

  4. 575 div 3 C. Robot Breakout

    C. Robot Breakout 题目大意: 一堆机器人,已知他们的初始位置(x,y),本来都可以向四个方向移动,但是一些原因,一个机器人的不能向某些方向移动,该方向能移动用1表示,否则用0 求他们 ...

  5. Codeforces Round #575 (Div. 3) 题解

    比赛链接:https://codeforc.es/contest/1196 A. Three Piles of Candies 题意:两个人分三堆糖果,两个人先各拿一堆,然后剩下一堆随意分配,使两个人 ...

  6. Codeforces Round #284 (Div. 2)A B C 模拟 数学

    A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard ...

  7. Codeforces Round #285 (Div. 2) A B C 模拟 stl 拓扑排序

    A. Contest time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  8. Codeforces Round #575 (Div. 3) B. Odd Sum Segments 、C Robot Breakout

    传送门 B题题意: 给你n个数,让你把这n个数分成k个段(不能随意调动元素位置).你需要保证这k个段里面所有元素加起来的和是一个奇数.问可不可以这样划分成功.如果可以打印YES,之后打印出来是从哪里开 ...

  9. Codeforces Round #461 (Div. 2) D. Robot Vacuum Cleaner

    D. Robot Vacuum Cleaner time limit per test 1 second memory limit per test 256 megabytes Problem Des ...

随机推荐

  1. php array function

    说明:不特殊说明都支持php4,5,7 参考:https://www.php.net/manual/zh/ref.array.php   is_array ( mixed $var ) : bool ...

  2. Android地图开发获取sHA1值方法

    public static String sHA1(Context context) { try { PackageInfo info = context.getPackageManager().ge ...

  3. React事件方法、React定义方法的几种方式、获取数据、改变数据、执行方法传值

    1.案例实现代码如下 import React, { Component } from 'react'; /** * 特别注意this,对于传值和绑定都十分重要 */ class Home4 exte ...

  4. pip Fatal error in launcher: Unable to create process using '""'

    如果你装了python2.7, python3.5, 在两个版本的兼容问题上折腾很久了,  通过修改环境变量, 能够出现下面的界面, 恭喜你, 暂时解决了一些问题, 哈哈

  5. 在java poi导入Excel通用工具类示例详解

    转: 在java poi导入Excel通用工具类示例详解 更新时间:2017年09月10日 14:21:36   作者:daochuwenziyao   我要评论   这篇文章主要给大家介绍了关于在j ...

  6. Apache Kafka系列(六)客制化Serializer和Deserializer

    已经迁移,请移步:http://www.itrensheng.com/archives/apache-kafka-repartition

  7. 对redis的一些理解

    缓存就是在内存中存储的数据备份,当数据没有发生本质变化的时候,我们避免数据的查询操作直接连接数据库,而是去    内容中读取数据,这样就大大降低了数据库的读写次数,而且从内存中读数据的速度要比从数据库 ...

  8. 分布式任务celery

    Celery的架构由三部分组成,消息中间件(message broker),任务执行单元(worker)和任务执行结果存储(task result store)组成. 消息中间件 Celery本身不提 ...

  9. python安装mongodb

    提前把mongodb-linux-x86_64-rhel70-3.2.4.tgz放到和脚本相同目录下,然后把下复制到脚本里面,开始执行 #!/usr/bin/python #-*- codinig: ...

  10. Springg MVC 中文乱码处理

    1.对于post请求的处理方式,在web.xml添加拦截器 <filter> <filter-name>CharacterEncodingFilter</filter-n ...