ans

caochenshuo 2023-11-25 10:18:35 2023-11-25 10:19:55 2 返回题目

#include <bits/stdc++.h>
using namespace std;
struct b{
    int w,l;
} t[2001];
bool cmp(b x,b y) {if (x.l!=y.l)return x.l<y.l;return x.w<y.w;}//cmp函数定义(定义比较规则)
bool f[2001];
int n,s,lst;
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) {
            s++;
            int lst = i;
            for (int j=i+1;j<=n; j++) {
                if (f[j] == false&&t[j].l>=t[lst].l&&t[j].w>=t[lst].w) {
                    f[j] = true;
                    lst = j;
                }
            }
        }
    }
    cout << s;
    return 0;
}
{{ vote && vote.total.up }}