全WA求助(悲)

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

huangzicheng114514 @ 2024-09-18 20:48:11

代码:

#include<bits/stdc++.h>//1j 2s cb 4
using namespace std;
#define ii int
#define ll long long
#define cc char
#define dd double
#define in cin
#define out cout
#define pp printf
#define bb bool
int main()
{
    int a,b,sum=0;
    in>>a>>b;
    bb s[a+10];
    for(int i=0;i<=a;i++){
        s[i]=true;//TODO
    }
    for(int i=0;i<b;i++){
        int z,x;
        cin>>z>>x;
        for(int j=z;j<=x;j++){
            s[j]=false;//TODO
        }

        //TODO
    }
    for(int i=0;i<=a;i++){
        if(s[i]=true){
            sum++;//TODO
        }//TODO
    }cout<<sum;     
    return 0;
}

by King_and_Grey @ 2024-09-18 20:50:20

@huangzicheng114514

码风比较丑,仅供借鉴

#include <bits/stdc++.h>
using namespace std;
#define int long long
int n,k,ans;
bool isok[100000];
struct node{
    int begin,end;
}a[105];

signed main(){
    cin >> n >> k;
    memset(isok,true,sizeof(isok));
    for (int i = 1; i <= k; i++){
        cin >> a[i].begin >> a[i].end;
    }
    for(int i = 1; i <= k; i++){
        for(int j = a[i].begin; j <= a[i].end ;j++){
            if(isok[j] == true){
                isok[j] = false;
            }
        }
    }
    for(int i = 0; i <= n ;i++){
        if(isok[i] == true){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

by lin20081016 @ 2024-09-18 20:50:59

最后一个循环的if,==写成=了


by huangzicheng114514 @ 2024-09-18 20:54:10

@lin20081016 6666


by Florrer_A @ 2024-09-18 20:54:39

@huangzicheng114514

#include<iostream>
using namespace std;
int main(){
    int l,m;
    cin >> l >> m;
    int *p = new int [l + 1];
    for(int i = 0;i < l + 1;i++){
        *(p + i) = 1;
    }
    for(int i = 0;i < m;i++){
        int temp1,temp2;
        cin >> temp1 >> temp2;
        for(int j = temp1;j <= temp2;j++){
            *(p+j)=0;
        }
    }
    int ans = 0;
    for(int i = 0;i < l + 1;i++){
        if(*(p + i)){
            ans++;
        }
    }
    cout << ans;
    return 0;
}

by huangzicheng114514 @ 2024-09-18 20:55:23

@lin20081016 AC了,谢啦!!!


by huangzicheng114514 @ 2024-09-18 20:56:22

@King_and_Grey 我的更陋。 (求关qwq)


by King_and_Grey @ 2024-09-18 20:56:43

@huangzicheng114514 ok


by huangzicheng114514 @ 2024-09-18 20:56:49

@lin20081016 (求关qwq)


by huangzicheng114514 @ 2024-09-18 21:06:32

@Florrer_A 已AC,求关QWQ


|