AtCoder Beginner Contest 243 C - Collision 2

C - Collision 2 Editorial


主要是学会unordered_map的一些用法:

#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>

#define x first
#define y second

using namespace std;
typedef pair<int, int> PII;

int main()
{
    int n;
    cin >> n;

    vector<PII> p(n + 10);
    string s;
    unordered_map<int, vector<PII>> h;
    for(int i = 0; i < n; i ++ )
        scanf("%d%d", &p[i].x, &p[i].y);

    cin >> s;


    for(int i = 0; i < n; i ++ )
        h[p[i].y].push_back({p[i].x, s[i] == 'R'? 1 : 0});

    bool flag = false;
    for(auto [a, b] : h)//h中的第一 第二元素
    {
        int r = 1e9, l = -1e9;

        for(auto [c, d] : b)//h中第二元素的 第一第二元素
        {
            if(d == 1)  r = min(r, c);
            else    l = max(l, c);
        }
        if(r < l)
        {
            flag = true;
            break;
        }
    }
    if(flag)    puts("Yes");
    else    puts("No");
    return 0;
}

更多关于unordered_map的用法请见:

(26条消息) c++ unordered_map4种遍历方式_菊头蝙蝠的博客-CSDN博客_c++ unordered_map 遍历

AtCoder Beginner Contest 243 C - Collision 2 - inss!w! - 博客园 (cnblogs.com)

posted @ 2022-03-13 16:52  bonel  阅读(59)  评论(0编辑  收藏  举报