哪里出问题了

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

Eletronic_Monkey @ 2024-10-15 21:01:23

#include<stdio.h>
int main()
{
    int length,number,count=0;
    scanf("%d %d",&length,&number);
    int arr1[number][2];
    int arr2[length];
    for(int i=0;i<number;i++)
    {
        scanf("%d %d",&arr1[i][0],&arr1[i][1]);
    }
    for(int j=0;j<number;j++)
    {
        for(int a=arr1[j][0];a<=arr1[j][1];a++)
        {

            arr2[a]=1;
        }
    }
    for(int b=0;b<length;b++)
    {
        if(arr2[b]==0)
        {
            count++;
        }
    }
    printf("%d",count);
    return 0;
}

by SunXiaolang @ 2024-10-15 21:09:14

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

    /*for (i=2;i<=n;i++){
        for (l=2;l<=sqrt(i);l++){
            if (i%l==0) break;
        }
        if (n%i==0){
            cout<<i;
            pdt*=i;
        }
        if (pdt==n) return 0;
    }*/
}

@Hope_to_grow Ac代码


by SunXiaolang @ 2024-10-15 21:09:46

注释不用看


|