只能输入一组u,v直接出结果,求调

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

alphabetaaaaaaa @ 2025-01-05 20:23:37

#include <iostream>

int main(){
    int l(1<=1<=10000),m(1<=m<=100);
    int s=0;
    std::cin>>l,m;
    int arr[l + 1] = {0};

    int u, v;  

    for (int i = 1; i <= m; i++){

        std::cin >> u >> v;

        for(int j = u; j <= v; j++){
            if(arr[j] == 0){
                arr[j]=1;}
        }
    }

    for(int i = 0; i <= l; i++){
        if (arr[i] == 0){
            s++;}
    }
    std::cout<< s <<std::endl;
    return 0;
}

by 4041nofoundGeoge @ 2025-01-05 20:27:10

int l(1<=1<=10000),m(1<=m<=100);

这是个什么语法


by Eason0324 @ 2025-01-05 20:28:38

std::cin>>l,m;

应该是

std::cin>>l>>m;

by 4041nofoundGeoge @ 2025-01-05 20:28:54

@alphabetaaaaaaa

#include <iostream>

int main(){
    int l,m;
    int s=0;
    std::cin>>l>>m;
    int arr[l + 1] = {0};

    int u, v;  

    for (int i = 1; i <= m; i++){

        std::cin >> u >> v;

        for(int j = u; j <= v; j++){
            if(arr[j] == 0){
                arr[j]=1;
            }
        }
    }

    for(int i = 0; i <= l; i++){
        if (arr[i] == 0){
            s++;}
    }
    std::cout<< s <<std::endl;
    return 0;
}求关

by Ziwiejun_jb_78 @ 2025-01-05 20:45:49

@alphabetaaaaaaa 这是啥?

int l(1<=1<=10000),m(1<=m<=100);

by alphabetaaaaaaa @ 2025-01-06 17:34:55

感谢!初学者还不太熟。


|