codeforce1196C
题意描述
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.
思路
遍历一遍机器人的坐标以及机器人所能进行的操作,求出向左最大能到达的坐标,向右最小能到达的坐标,向上和向下能到达的坐标,最后判断向左和向下能够到达的坐标是否小于向右和向上能够到达的坐标,输出左下的坐标即可。
AC代码
#include<bits/stdc++.h>
#define x first
#define y second
#pragma GCC optimize(2)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize(3)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target("sse3","sse2","sse")
#pragma GCC target("avx","sse4","sse4.1","sse4.2","ssse3")
#pragma GCC target("f16c")
#pragma GCC optimize("inline","fast-math","unroll-loops","no-stack-protector")
#pragma GCC diagnostic error "-fwhole-program"
#pragma GCC diagnostic error "-fcse-skip-blocks"
#pragma GCC diagnostic error "-funsafe-loop-optimizations"
#pragma GCC diagnostic error "-std=c++14"
#define IOS ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef long long LL;
const int N=1e5+10;
const int M=150;
const int INF=0x3f3f3f3f;
const int MOD=998244353;
int main(){
IOS;
int T;cin>>T;
while(T--){
int n;cin>>n;
int maxx=100000,minx=-100000,maxy=100000,miny=-100000;
for(int i=0;i<n;i++){
int x,y,l,r,u,d;cin>>x>>y>>l>>u>>r>>d;
if(!l) minx=max(minx,x);
if(!u) maxy=min(maxy,y);
if(!r) maxx=min(maxx,x);
if(!d) miny=max(miny,y);
}
if(minx<=maxx && miny<=maxy){
cout<<"1 "<<minx<<' '<<miny<<endl;
}else{
cout<<"0"<<endl;
}
}
return 0;
}
- sql初始化XML操作
- 给你一根杠杆,撬起万亿的小程序红利市场!
- Flash/Flex学习笔记(43):动量守恒与能量守恒
- Flash/Flex学习笔记(57):实用技巧
- 使用 MEF 轻松实现云部署
- 检测常见ASP.NET配置安全漏洞
- Flash/Flex学习笔记(56):矩阵变换
- js小技巧:tab页切换
- c#字符串操作方法实例
- Android中Fragment+ViewPager的配合使用
- 结合机器学习与生物医学技术,寻找Uber司机出行模式
- ASP.NET MVC 4 - 测试驱动 ASP.NET MVC
- LVS+Keepalived高可用环境部署梳理(主主和主从模式)
- 随着区块链的火爆,相关顶级域名“矿池”KC.com已建站
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 数据结构严书习题6.65已知前中序,求二叉链表
- 【Java】10 Deque 接口
- 12.深入k8s:kubelet创建pod流程源码分析
- (较为详细)树的遍历方式一览(附完整源码可在VScode与cb运行)
- 【Java】12 Map 集合
- 【Java】11 Set 集合
- 4.表格-HTML基础
- 2.语义化-HTML进阶
- MATLAB 与 C 语言的混合编程
- leetcode树之二叉树的层平均值
- C++雾中风景15:聊聊让人抓狂的Name Mangling
- 【Java】15 File 类
- seaborn更高效的统计图表制作工具
- 牛客2019跨年AK场题解(一)
- qiankun proxySand 沙箱