CF575div3 C题

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
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
模拟题,不断更新可行范围,如果新机器人达不到这个范围则返回0

#include<stdio.h>
#include<algorithm>
#define INF 100000
using namespace std;
int q,n,x,y,flag,rx,lx,ry,ly,a1,a2,a3,a4;
int main()
{
	scanf("%d",&q);
	while(q--)
	{
		flag=1;
		rx=ry=INF;
		lx=ly=-INF;
		scanf("%d",&n);
		while(n--)
		{
			scanf("%d%d%d%d%d%d",&x,&y,&a1,&a2,&a3,&a4);
			if(flag)
			{
				if(a1==0)
				{
					if(x>rx)
					{
						flag=0;
						continue;
					}
					lx=max(lx,x);
				}				
				if(a2==0)
				{
					if(y<ly)
					{
						flag=0;
						continue;
					}
					ry=min(ry,y);
				}
				
				if(a3==0)
			    {
			    	if(x<lx)
					{
						flag=0;
						continue;
					}
					rx=min(rx,x);
				}
				
				if(a4==0)
				{
					if(y>ry)
					{
						flag=0;
						continue;
					}
					ly=max(ly,y);
				}
				
			}
		}
		if(flag)
		printf("1 %d %d\n",lx,ly);
		else
		printf("0\n");
	}
}
在 Codeforces 平台上,评分(rating)为 1600 到 2500 的目通常属于中等到较难的范围。然而,其中一些目虽然评分较高,但其解法相对简单,但由于细节实现、边界条件处理或思维误区,容易导致错误(WA)。这类目往往对算法思维和实现细节要求较高,但并不一定需要复杂的算法知识。 ### 目类型和特点 以下是一些在 1600 到 2500 评分区间内,相对简单但容易出错的目类型: - **贪心算法**:例如区间调度、最大覆盖等,容易因为贪心策略选择不当导致错误[^1]。 - **二分查找**:边界条件(如 `low <= high` 或 `low < high`)的误判,可能导致无限循环或错误结果[^1]。 - **字符串处理**:正则表达式、模式匹配、特殊字符处理等,容易因输入格式不规范或边界条件而出现错误[^1]。 - **模拟**:逻辑复杂但不涉及高级算法,可能因为细节处理不当出错[^1]。 ### 推荐练习策略 1. **筛选目**:可以使用 Codeforces 的标签筛选功能,结合以下标签进行练习: - `implementation` - `greedy` - `binary search` - `math` - `constructive algorithms` 2. **关注“WA 高发”**:在 Codeforces 上,可以关注那些通过率较低(如 AC Submission Ratio 较低)的目,这类目通常存在陷阱[^1]。 3. **练习经典**: - **Codeforces Round #603 (Div. 2) - Problem B**:涉及数学思维,容易在边界条件上出错[^1]。 - **Codeforces Round #598 (Div. 3) - Problem D**:关于二分查找,实现时容易出现逻辑错误[^1]。 - **Codeforces Round #616 (Div. 2) - Problem C**:贪心策略应用,但需要仔细处理特殊情况[^1]。 ### 示例代码 以下是一个简单的二分查找实现,展示了如何避免常见的边界条件错误: ```python def binary_search(arr, target): left, right = 0, len(arr) - 1 while left <= right: mid = (left + right) // 2 if arr[mid] == target: return mid elif arr[mid] < target: left = mid + 1 else: right = mid - 1 return -1 ``` 该实现通过 `while left <= right` 保证了所有可能的区间都被覆盖,并且在每次循环中正确更新 `left` 和 `right` 的值,从而避免无限循环或遗漏目标值的情况[^1]。 ###
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值