错了。。。。

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

Cerecry__mind @ 2024-03-17 09:56:36

#include<bits/stdc++.h>
using namespace std;
int arr[10000] = {0};
int main(){
    int l, m;
    cin >> l>>m;
    int x,y;
    int ans = 0;
    for (int i = 0;i<m;i++){
        cin >> x>> y;
            for(int j = x;x<=y;j++){
                arr[x] = 1;
        }

}

    for (int k = 0; k<=l;k++){
        if(arr[k]== 0)
            ans++;

    }
    cout << ans;
    return 0;
}

by WydnksqhbD @ 2024-03-17 09:59:54

@Cerecry__mind 这么简单的题目能不能自己改?


by Cerecry__mind @ 2024-03-17 10:05:19

@WydnksqhbD 关键我感觉很对


by quxiangyu @ 2024-03-17 10:07:28

@Cerecry__mind 求关注

#include<bits/stdc++.h>
using namespace std;
int L , M;
int cnt = 0;
int vis[100000000];
int main()
{
    memset(vis , 0 , sizeof(vis));
    cin >> L >> M;
    for(int i = 0 ; i <= L; ++i)
        vis[i] = 0;
    for(int i = 1 ; i <= M ; ++i) {
        int head , tail;
        cin >> head >> tail;
        for(int j = head ; j <= tail ; ++j)
            if(vis[j] == 0)
                vis[j] = 1;
    }
    for(int i = 0 ; i <= L; ++i) {
        if(vis[i] == 0)
            cnt ++;
    }
    cout << cnt << end;
    return 0;
}

by ComistryMo @ 2024-03-17 12:00:39

#include<bits/stdc++.h>
using namespace std;
int arr[10000] = {0};
int main(){
    int l, m;
    cin >> l>>m;
    int x,y;
    int ans = 0;
    for (int i = 0;i<m;i++){
        cin >> x>> y;
            for(int j = x;j<=y;j++){
                arr[j] = 1;
        }

}

    for (int k = 0; k<=l;k++){
        if(arr[k]== 0)
            ans++;

    }
    cout << ans;
    return 0;
}

by ComistryMo @ 2024-03-17 12:01:16

@Cerecry__mind 看看我的回复 你的内层循环写错了


by Cerecry__mind @ 2024-03-18 12:04:31

@Cerecry__mind 感谢,改好了


|