全部WA,求助

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

HuTaoJiaZiBuJia @ 2024-09-06 18:53:24

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

全WA了,插粪做的,沃步里姐


by pmkmzfuzsotqotmzs @ 2024-09-06 19:26:45

@HuTaoJiaZiBuJia

#include<iostream>
using namespace std;
bool b[10001];
int main()
{
    int l,m;
    cin>>l>>m;

    for(int i=1;i<=m;i++)
    {
        int u,v;
        cin>>u>>v;
        for(int j=u;j<=v;j++)
            b[j]=1;
    }
    int sum=0;
    for(int i=0;i<=l;i++)
    {
        if(b[i]==0)
            sum++;
    }
    cout<<sum<<endl;
    return 0;
}

by pmkmzfuzsotqotmzs @ 2024-09-06 19:29:22

@HuTaoJiaZiBuJia 你的代码连输入都有问题:
cin>>t1,t2; ,你的思路也不对


by wangxiaoyi1118 @ 2024-09-06 19:32:38

@HuTaoJiaZiBuJia 孩子,多练吧,

#include<bits/stdc++.h>
using namespace std;
int a[10001],s[101],e[101];
int main()
{
    int L,M;
    int ans=0;
    cin>>L>>M;
    for(int i=0;i<M;i++)
    {
        cin>>s[i]>>e[i];
        for(int j=s[i];j<=e[i];j++)
        {
            a[j]=1; 
        }
    }
    for(int i=0;i<=L;i++)
    {
        if(a[i]==0)
        {
            ans++;
        }
    }
    cout<<ans;
    return 0;
} 

我不是因为头像点进的


by like_dzpd_ @ 2024-09-06 19:38:03

@HuTaoJiaZiBuJia wo以前写的,可以看一下~```c

include<bits/stdc++.h>

using namespace std; int main(){ bool a[10005]; int cnt=0; int l,n; cin>>l>>n; for(int i=0;i<=l;i++){ a[i]=1; } int x,y; while(n--){ cin>>x>>y; for(int i=x;i<=y;i++){ a[i]=0; } } for(int i=0;i<=l;i++){ if(a[i]==1){ cnt++; } } cout<<cnt; return 0; }


by like_dzpd_ @ 2024-09-06 19:38:21

e


by like_dzpd_ @ 2024-09-06 19:38:36

#include<bits/stdc++.h>
using namespace std;
int main(){
    bool a[10005];
    int cnt=0;
    int l,n;
    cin>>l>>n;
    for(int i=0;i<=l;i++){
        a[i]=1;
    }
    int x,y;
    while(n--){
        cin>>x>>y;
        for(int i=x;i<=y;i++){
            a[i]=0;
        }
    }
    for(int i=0;i<=l;i++){
        if(a[i]==1){
            cnt++;
        }
    }
    cout<<cnt;
    return 0;
}

by HuTaoJiaZiBuJia @ 2024-09-06 20:14:53

@pmkmzfuzsotqotmzs 你真好!


by HuTaoJiaZiBuJia @ 2024-09-06 20:15:15

@pmkmzfuzsotqotmzs 完了,我是蒟蒻!!


by HuTaoJiaZiBuJia @ 2024-09-06 20:15:44

@wangxiaoyi1118 yuan lai ni ye wan yuan shen


by wangxiaoyi1118 @ 2024-09-06 20:19:16

@HuTaoJiaZiBuJia 原神几级?我51


| 下一页