题解

luozhiyi 2023-11-18 15:41:41 4 返回题目

#include <bits/stdc++.h>
using namespace std;
struct task {
    int l, w;
} t[2000];
bool cmp(task x, task y) {
    if (x.l != y.l)
        return x.l < y.l;
    else
        return x.w < y.w;
}
bool f[2000];
int n, ans, last;
int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> t[i].l >> t[i].w;
    sort(t + 1, t + n + 1, cmp);
    for (int i = 1; i <= n; i++) f[i] = false;
    for (int i = 1; i <= n; i++) {
        if (f[i] == false) {
            ans++;
            int last = i;
            for (int j = i + 1; j <= n; j++) {
                if (f[j] == false && t[j].l >= t[last].l && t[j].w >= t[last].w) {
                    f[j] = true;
                    last = j;
                }
            }
        }
    }
    cout << ans;
    return 0;
}
{{ vote && vote.total.up }}