LLjj123456 @ 2023-01-12 23:30:57
n,b=map(int,(input().split())) a=[] temp=[] for i in range(b): s=list(map(int,(input().split()))) for j in range(int(s[0]),int(s[1])+1): a.append(j) for c in a: if not c in temp: temp.append(c) print(n+1-len(temp))
by Eznibuil @ 2023-01-12 23:36:33
@LLjj123456 望丰展?使MD。
by zhanghanzhou @ 2023-01-18 10:11:21
@LLjj123456 你可以使用如下代码
#include<bits/stdc++.h>
using namespace std;
int a[10010];
int main()
{
int L,m,x,y,s=0;
cin>>L>>m;
for(int i=1;i<=m;i++)
{
cin>>x>>y;
for(int j=x;j<=y;j++)
a[j]=1;
}
for(int i=0;i<=L;i++)
if(a[i]==0)s++;
cout<<s;
return 0;
}
肯定能过