目录
算法笔记3.1小节(编号100000575)——入门模拟->简单模拟
算法笔记3.1小节(编号100000575)——入门模拟->简单模拟
A:剩下的树
1428KB | 3ms | C++ | 399 bytes |
#include <cstdio>
#include <cstring>
int T[10010];
int main() {
int L,M;
while(scanf("%d%d", &L,&M)!=EOF,L||M){ //读到文件末尾,并保证L和M不是0
memset(T,0,sizeof(T)); //重置数组T
int a,b;
while(M--){
scanf("%d%d",&a,&b);
for(int i=a;i<=b;i++){
T[i]++;
}
}
int count=0;
for(int i=0;i<=L;i++){
if(!T[i]) count++; //找出数组中状态未变(为0)的元素个数
}