解题思路:
利用标记数组
注意事项:
明确端点是否包含其中
参考代码:
#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 count=0;
for(int i=0;i<l+1;i++)
if(*(p+i)) count++;
cout<<count<<endl;
return 0;
}
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题7.3 (C语言代码)浏览:588 |
C语言程序设计教程(第三版)课后习题6.1 (C语言代码)浏览:634 |
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:1472 |
回文串 (C语言代码)浏览:2070 |
这可能是一个假的冒泡法浏览:869 |
C语言训练-求函数值 (C语言代码)浏览:533 |
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:756 |
剪刀石头布 (C语言代码)浏览:660 |
【绝对值排序】 (C语言代码)浏览:753 |
C语言程序设计教程(第三版)课后习题6.2 (C语言代码)浏览:593 |