5 solutions

  • 1
    @ 2024-11-8 10:34:15
    #include<bits/stdc++.h>
    using namespace std;
    const int N=10010;
    int a[N];
    int main()
    {
    	int L,m;
    	cin>>L>>m;
    	for(int i=1;i<=m;i++) //枚举区间个数 
    	{
    		int l,r;
    		cin>>l>>r;
    		for(int j=l;j<=r;j++) //标记区间l到r之间的所有数 
    		{
    			a[j]=1;
    		}
    	}
    	int c=0;
    	for(int i=0;i<=L;i++) //判断整个区间的每个位置 
    	{
    		if(a[i]==0)
    		{
    			c++;
    		}
    	}
    	cout<<c;
    	return 0;
    }
    
    • 1
      @ 2024-4-20 11:56:28
      #include<bits/stdc++.h>
      using namespace std;
      const int N=10010;
      int a[N];
      int main()
      {
      	int L,m;
      	cin>>L>>m;
      	for(int i=1;i<=m;i++)
      	{
      		int l,r;
      		cin>>l>>r;
      		for(int j=l;j<=r;j++)
      		{
      			a[j]=1;
      		}
      	}
      	int cnt=0;
      	for(int i=0;i<=L;i++)
      	{
      		if(a[i]==0)
      		{
      			cnt++;
      		}
      	}
      	cout<<cnt;
          return 0;
      }
      
      
      • -2
        @ 2025-1-13 14:48:27
        #include<bits/stdc++.h>
        using namespace std;
        const int N=10010;
        int a[N];
        int main()
        {
        	int n,m;
        	cin>>n>>m;
        	for(int i=1;i<=m;i++)
        	{
        		int l,r;
        		cin>>l>>r;
        		for(int j=r;j<=l;j++)
        		{
        			a[r]=1;
        		}
        	}
        	int cnt=0;
        	for(int i=1;i<=l;i++)
        	{
        		if(a[r]>>1)
        		{
        			cnt--;
        		}
        	}
        	cout<<cnt;
            return 0;
        }
        
        
        
        
        • -4
          @ 2024-11-18 18:53:19
          
          
          • -6
            @ 2024-11-18 18:53:42
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            • 1

            Information

            ID
            895
            Time
            1000ms
            Memory
            256MiB
            Difficulty
            3
            Tags
            (None)
            # Submissions
            141
            Accepted
            47
            Uploaded By