壹拾分整(c++)

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

one_OIER @ 2022-07-05 16:18:21

#include <bits/stdc++.h>
using namespace std;
int n , m , l , r;
bool vis[10110];
int main() {
    cin >> n >> m;
    for(int i = 1;i <= n;++i) {
        vis[i] = false;
    }
    while(m--) {
        cin >> l >> r;
        for(int i = l;i <= r;++i) {
            vis[i] = true;
        }
    }
    int ans = 0;
    for(int i = 1;i <= n;++i) {
        if(vis[i] == false) ans++;
    }
    cout << ans << endl;
    return 0;
}

by one_OIER @ 2022-07-05 16:19:50

吾有一言,曰:“不解”,书之。


by ShouZheng_Observer @ 2022-07-05 16:21:41

@qianchengqq 注意边界噻


by Trinitrotoluene @ 2022-07-05 16:22:38

@qianchengqq 马路的一端在数轴 0 的位置


by ioker @ 2022-07-05 16:28:47

@qianchengqq 建议左转至语文竞赛


by one_OIER @ 2022-07-05 16:30:30

@dpkajj ......


by one_OIER @ 2022-07-05 16:31:40

#include <bits/stdc++.h>
using namespace std;
#define int long long
int n , m , l , r;
bool vis[10110];
signed main() {
    cin >> n >> m;
    for(int i = 0;i < n;++i) {
        vis[i] = false;
    }
    while(m--) {
        cin >> l >> r;
        for(int i = l;i <= r;++i) {
            vis[i] = true;
        }
    }
    int ans = 0;
    for(int i = 0;i < n;++i) {
        if(vis[i] == false) ans++;
    }
    cout << ans << endl;
    return 0;
}

30分......


by one_OIER @ 2022-07-05 16:32:42

@qianchengqq 哦,不对,是叁拾分整


by StarLbright40 @ 2022-07-05 16:36:53

有没有一种可能,区间是 [0,n],既不是 (0,n] 也不是 [0,n)


by ShouZheng_Observer @ 2022-07-05 16:49:57

#include <bits/stdc++.h>
using namespace std;
int n , m , l , r;
bool vis[10110];
int main() {
    cin >> n >> m;
    for(int i = 0;i <= n;++i) {
        vis[i] = false;
    }
    while(m--) {
        cin >> l >> r;
        for(int i = l;i <= r;++i) {
            vis[i] = true;
        }
    }
    int ans = 0;
    for(int i = 0;i <= n;++i) {
        if(vis[i] == false) ans++;
    }
    cout << ans << endl;
    return 0;
}

这个看一下,应该是AC的代码,


by ShouZheng_Observer @ 2022-07-05 16:52:33

@星光0000 有没有可能是(0,n)


| 下一页