C - Collision 2 (atcoder.jp)
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
#define x first
#define y second
const int M = 1e6;
typedef pair<int, int>pill;
pill p[M];
map<int, vector<pill>>mp;
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> p[i].x >> p[i].y;
}
string str;
cin >> str;
for (int i = 0; i < n; i++)
{
mp[p[i].y].push_back({ p[i].x,str[i] == 'R' ? 0 : 1 });
}
for (auto i : mp)
{
sort(i.y.begin(), i.y.end(), [](pill a, pill b)
{
return a.x < b.x;
}
);
int l = i.y.size();
for (int j = 0; j <l ; j++)
{
if (i.y[j].y == 0)
{
for (int k = j + 1; k < l; k++)
{
if (i.y[k].y == 1)
{
cout << "Yes" << endl;
return 0;
}
}
}
}
}
cout << "No" << endl;
return 0;
}
不过用STL可能有点绕 所以也可以用结构体排序
//#pragma GCC optimize(2)
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <ctime>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
using ll = long long;
const int N = 2e5 + 7;
const long long INF = 0x3f3f3f3f3f3f3f3f;
typedef pair<int, int> PII;
#define ff first
#define ss second
PII p[N];
char str[N];
map<int, vector<PII>> mp;
int n;
struct f
{
int x;
int y;
char s;
}q[N];
void init()
{
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> q[i].x >> q[i].y;
}
string st;
cin >> st;
for (int i = 0; i < n; i++)
{
q[i].s = st[i];
}
}
void work()
{
sort(q, q + n, [](f a, f b)
{
if (a.y == b.y)
{
return a.x < b.x;
}
return a.y < b.y;
}
);
for (int i = 0; i < n-1; i++)
{
if (q[i].y == q[i + 1].y && q[i].s == 'R' && q[i + 1].s == 'L')
{
cout << "Yes" << endl;
return;
}
}
cout << "No" << endl;
}
int main() {
int T = 1;
// scanf("%d",&T);
while (T--) {
init();
work();
}
return 0;
}
|