当前位置: 首页 > 工具软件 > collision > 使用案例 >

C - Collision 2

戎永福
2023-12-01
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
const int N = 2e5 + 10;
struct Node
{
	int x, y, d;
}nodes[N];
int n;

//按照行排序后 可以逐行分析
//在行内按照列排列后进行逐列分析
//当发现方向不同的两个元素时
//始终前者x小后者x大
bool cmp(Node a, Node b)
{
	if (a.y != b.y)return a.y < b.y;
	return a.x < b.x;
}

int main()
{
	cin >> n;
	for (int i = 0;i < n;i++)cin >> nodes[i].x >> nodes[i].y;

	string str;cin >> str;
	for (int i = 0;i < n;i++)
	{
		//将表示方向的字母 L R 压缩为数字 0 1
		if (str[i] == 'L')nodes[i].d = 0;
		else nodes[i].d = 1;
	}
	
	sort(nodes, nodes + n, cmp);

	for (int i = 0;i < n - 1;i++)
	{
		//只考虑一行内的
		if (nodes[i].y == nodes[i + 1].y)
		{
			//前者朝右 后者朝左
			if (nodes[i].d == 1 && nodes[i + 1].d == 0)
			{
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

 类似资料: