AcWing
  • 首页
  • 活动
  • 题库
  • 竞赛
  • 商店
  • 应用
  • 文章
    • 题解
    • 分享
    • 问答
  • 吐槽
  • 登录/注册

AcWing 1978. 奶牛过马路 0.04 AC币

作者: 作者的头像   4_3 ,  2022-01-10 23:03:41 ,  所有人可见 ,  阅读 14


0


#include <iostream>
#include <cstring>
#include <algorithm>

#define x first
#define y second

using namespace std;

typedef pair<int, int> PII;

const int N = 1e5 + 10;

PII pa[N];
int pe[N], ps[N];
int n, ans;


int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i ++)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        pa[i] = {a, b};
    }
    sort(pa, pa + n);

    ps[0] = pa[0].y;
    for (int i = 1; i < n; i ++)
        ps[i] = max(ps[i - 1], pa[i].y);

    pe[n - 1] = pa[n - 1].y;
    for (int i = n - 2; i >= 0; i --)
        pe[i] = min(pe[i + 1], pa[i].y);

    for (int i = 0; i < n; i ++)
        if (ps[i] == pe[i])
            ans ++;

    printf("%d", ans);

    return 0;
}

0 评论

你确定删除吗?
1024
x

© 2018-2022 AcWing 版权所有  |  京ICP备17053197号-1
用户协议  |  常见问题  |  联系我们
AcWing
请输入登录信息
更多登录方式: 微信图标 qq图标
请输入绑定的邮箱地址
请输入注册信息