90WA求助

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

dami826 @ 2022-10-23 19:55:35

#include<iostream>
using namespace std; 

int main(){
    int a,n,s=0;
    cin>>a>>n;
    bool A[a+1];
    for(int k=1;k<=a+1;k++){
        A[k]=true;
    }
    for(int i=1;i<=n;i++){
        int x,y;
        cin>>x>>y;
        for(int j=x;j<=y;j++){
            A[j]=false; 
        }
    }
    for(int l=1;l<=a+1;l++){
        if(A[l]==true){
            s++;
        }
    }
    cout<<s;
    return 0;
}

by dami826 @ 2022-10-23 19:59:51

第一个测试点WA,其他都AC


by 2011Andy @ 2022-10-27 21:42:15

借鉴一下我的求关注QAQ

#include<bits/stdc++.h>
using namespace std;
int c[10010];
int main(){
    int  n , m , a[105] , b[105] , sum = 0;
    cin >> n >> m;
    for(int i = 0 ; i <= 10010 ; i++){
        c[i] = 1;
    }
    for(int i = 1 ; i <= m ; i++){
        cin >> a[i] >> b[i];
        for(int j = a[i] ; j <= b[i] ; j++){
            if(c[j] == 1){
                c[j] = 0;
            }
        }
    }
    for(int i = 0 ; i <= n ; i++){
        if(c[i] == 1){
            sum++;
        }
    }
    cout << sum;
    return 0;
}

|