蒟蒻贴(测试点一错了)

P1047 [NOIP2005 普及组] 校门外的树

zjy0419 @ 2024-10-05 21:44:05

#include <bits/stdc++.h>
using namespace std;

int main() {
    int l, b;
    cin >> l >> b;
    l++;
    bool n[l] = {};

    for (int i = 0; i < l; i++) {
        n[i] = 1;
    }

    int t, w;
    for (int i = 1; i <= b; i++) {
        cin >> t >> w;
        for (int j = t - 1; j < w; j++) {
            n[j] = 0;
        }
    }

    int x = 0;
    for (int i = 0; i < l; i++) {
        if (n[i]) {
            x++;
        }
    }
    cout << x;
}

我写代码还是挺漂亮的好吧


by Reduct @ 2024-10-05 21:46:59

突然想起来我也前也喜欢用变量(而非常量)定义数组大小


by lsd110504 @ 2024-10-05 21:52:40

for (int i = 1; i <= b; i++) { cin >> t >> w;

for (int j = t ; j <= w; j++) {

        n[j] = 0;
    }
}
这样就过了,没考虑后边界

by zjy0419 @ 2024-10-05 22:04:14

@lsd110504 感谢。


by zjy0419 @ 2024-10-05 22:05:00

@Reduct °v°


|