Newcoder white race May 20 H good point

Newcoder white race May 20 H good point

Feel good and then took out.

After we read the questions we seek to getting a few will find a bunch, then these numbers must be decreasing.

Anyway, I want to come out after 5min finished it ..

Yy himself look like.

code

#include <bits/stdc++.h>

#define N 500010
#define M 1010

using namespace std;
int n, a, b, sum;
struct node {
    int a, b;
}point[N], ans[N];

int read() {
    int s = 0, f = 0; char ch = getchar();
    while (!isdigit(ch)) f |= (ch == '-'), ch = getchar();
    while (isdigit(ch)) s = s * 10 + (ch ^ 48), ch = getchar();
    return f ? -s : s;
}

bool cmp(node a, node b) {
    return a.a == b.a ? a.b > b.b : a.a > b.a;
}

bool cmp2(node a, node b) {
    return a.a < b.a;
}

int main() {
    n = read();
    for (int i = 1; i <= n; i++)
        point[i].a = read(), point[i].b = read();
    sort(point + 1, point + n + 1, cmp);
    int mii = point[1].b;
    ans[1].a = point[1].a, ans[1].b = point[1].b, sum = 1;
    for (int i = 2; i <= n; i++) {
        if (mii < point[i].b) {
            mii = point[i].b;
            ans[++sum].a = point[i].a;
            ans[sum].b = point[i].b;
        }
    }
    sort(ans + 1, ans + sum + 1, cmp2);
    for (int i = 1; i <= sum; i++)
        cout << ans[i].a << " " << ans[i].b << "\n";
    return 0;
}

Guess you like

Origin www.cnblogs.com/zzz-hhh/p/12078498.html