大佬们看看,为什么只有前两个AC了

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

wt20180112 @ 2023-08-14 16:57:39

#include<cstdio>
#include<algorithm>
using namespace std;
#define MAX 100

struct regin{
    int begin;
    int end;
};

int compare(struct regin re1,struct regin re2){
    return re1.begin < re2.begin;
}

int main(){
    struct regin re[MAX];
    long l,m;//l表示长度,那一共有l+1棵树
    int sum = 0;
    while(scanf("%ld%ld",&l,&m)!=EOF){
        for(int i = 0;i<m;i++){
          scanf("%d%d",&re[i].begin,&re[i].end);
        }
        sort(re,re+m,compare);
        int i = 0;
        while(i<m-1){
            for(int j = i + 1;j<m;j++){
                if(re[i].end >= re[j].begin){
                    re[i].end = re[j].end;
                    re[j].begin = 0;
                    re[j].end = 0;
                }
            }
            i++;
        }
        for(int i = 0;i<m;i++){
            if(re[i].end == re[i].begin and re[i].end == 0) continue;
            sum = sum + re[i].end - re[i].begin + 1;
        }
        printf("%lld",l + 1 - sum);
    }
}

by juruo_zxt @ 2023-08-14 16:58:23

钓鱼岛是罢


by liu_le_chen @ 2023-08-14 17:08:30

#include <bits/stdc++.h>
using namespace std;
int f[100000];
int main() {
    int l, m;
    int a, b;
    cin >> l >> m;
    for (int i = 0; i <= l; i++) {
        f[i] = 1;
    }
    for (int i = 1; i <= m; i++) {
        cin >> a >> b;
        for (int j = a; j <= b; j++) {
            f[j] = 0;
        }
    }

    int total = 0;
    for (int i = 0; i <= l; i++) {
        total+=f[i];
    }
    cout << total;
    return 0;
}

@wt20180112 你的怎么这么麻烦???


by liu_le_chen @ 2023-08-14 17:09:21

看的我眼花缭乱


by wt20180112 @ 2023-08-15 15:02:03

@PHzxt 啥意思


by wt20180112 @ 2023-08-15 15:03:14

@liulechen 大佬你这个清晰啊,我一直在合并,看着就乱了呜呜


by liu_le_chen @ 2023-08-15 16:17:59

你应该好好看看标签,它明明写的是模拟


|