80分求助,#8 #9报错

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

final_deterrence @ 2024-08-09 10:00:42


#include<stdio.h>

int main()
{
    int a[10001];
    int l,m;
    int i,j;
    int num;
    int b[100][2];
    scanf("%d %d\n",&l,&m);
    num=l+1;
    for(i=0;i<m;i++)
    {
        scanf("%d %d",&b[i][0],&b[i][1]);
    }
    for(i=0;i<m;i++)
    {
        for(j=0;j<=l;j++)
        {
            if(b[i][0]<=j&&b[i][1]>=j)
            {
                a[j]=1;
            }
        }
    }
    for(i=0;i<=l;i++)
    {
        if(a[i]==1)
        {
            num=num-1;
        }
    }
    printf("%d",num);   
    return 0;
}

by Greeper @ 2024-08-09 10:02:54

@final_deterrence

#include<iostream>
using namespace std;
int main()
{
    int l,m;
    cin>>l>>m;
    bool a[l+1];
    for(int i=0;i<=l;i++)
    {
        a[i]=1;
    }
    int s,e;
    for(int i=1;i<=m;i++)
    {
        cin>>s>>e;
        for(int j=s;j<=e;j++)
        {
            a[j]=0;
        }
    }
    int sum=0;
    for(int i=0;i<=l;i++)
    {
        sum+=a[i];
    }
    cout<<sum;
}

以A求关谢谢


by Greeper @ 2024-08-09 10:03:38

@final_deterrence 目测是你代码b数组开小了


by final_deterrence @ 2024-08-09 10:11:52

@Greeper 改大后还是不行┻┳|・ω・),而且把O2优化关掉后#8就能过


by Greeper @ 2024-08-09 10:14:33

@final_deterrence ???


by final_deterrence @ 2024-08-09 10:28:53

不明白,开摆qwq


by final_deterrence @ 2024-08-09 11:22:09

改了一下计数方式就过了


|