解题思路:
注意事项:
参考代码:
#include<iostream>
using namespace std;
int main()
{
int L,M;
cin>>L>>M;
int qishi[100],zhongzhi[100];
for(int i=0;i<M;i++)
{
cin>>qishi[i]>>zhongzhi[i];
}
int shu[10000]; //to describe trees' situations
for(int i=0;i<=L;i++) //1 existed
{ //0 destroyed
shu[i]=1;
for(int j=0;j<M;j++)
{
if(i>=qishi[j]&&i<=zhongzhi[j])
{
shu[i]=0;
}
}
}
int out=0;
for(int i=0;i<=L;i++)
{
if(shu[i]==1)
{ out++;
}
}
cout<<out<<endl;
return 0;
}
0.0分
0 人评分