RE 求助,找了 POJ 的样例过了
查看原帖
RE 求助,找了 POJ 的样例过了
724958
lixuanyan楼主2022/5/14 18:19
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define maxn 1005
int n, sum, cnt;
double d;
double last = -1e9;
double l[maxn], r[maxn];
struct coord {
    double x, y;
} t[maxn];

int read() {
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') { f = (ch == '-' ? -1 : f); ch = getchar(); }
    while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
    return x * f;
}

bool cmp(coord a, coord b) {
    return a.x <= b.x;
}

void empty() {
    last = -1e9, sum = 0;
    memset(l, 0, sizeof(l));
    memset(l, 0, sizeof(r));
    memset(l, 0, sizeof(t));
}

double get_min(double a, double b) {
    return a < b ? a : b;
}

signed main() {
    while ((n = read()) != 0 && (d = read()) != 0) {
        empty();
        for (int i = 1; i <= n; i++) cin >> t[i].x >> t[i].y;
        sort(t + 1, t + 1 + n, cmp);
        for (int i = 1; i <= n; i++) {
            int x = t[i].x, y = t[i].y;
            double dis = sqrt(d * d - y * y);
            l[i] = x - dis, r[i] = x + dis;
        }
        for (int i = 1; i <= n; i++) {
            if (l[i] > last) sum++, last = r[i];
            else last = get_min(last, r[i]);
        }
        cout << "Case " << ++cnt << ": ";
        cout << sum << endl;
    }
    return 0;
}

2022/5/14 18:19
加载中...