第36551题 组合题
阅读程序(第三题):最多不重叠区间选择

阅读下面程序,完成后面的判断题和单选题。判断题正确填 A,错误填 B。

#include <algorithm>
#include <cstdio>

struct Seg {
    int l, r;
};

Seg a[100005];

bool cmp(const Seg &x, const Seg &y) {
    return x.r < y.r;
}

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
        scanf("%d%d", &a[i].l, &a[i].r);
    std::sort(a + 1, a + n + 1, cmp);
    int cnt = 0, last = -1000000000;
    for (int i = 1; i <= n; ++i) {
        if (a[i].l >= last) {
            ++cnt;
            last = a[i].r;
        }
    }
    printf("%d\n", cnt);
    return 0;
}
{{ option.label }}
子题{{ index + 1 }} {{ child.type_label }}
{{ option.label }}
✓ 正确 ◐ 部分正确 ✗ 错误
程序运行统计
暂无判题统计
知识点:
提交{{ questionInfo.stats ? questionInfo.stats.submit_count : 0 }}次 正确率{{ statsAccuracy }}%
答案解析