Topic 1088: The remaining trees
time limit:1 seconds
Memory limit:32 MB
Special question: No
submitted:4253
Resolution:1907
-
Title Description:
-
There is a length of the whole number of L (1<=l<=10000) of the road, you can imagine the length of the axis of a line of L, the starting point is the origin of the coordinates, at each integer coordinate point there is a tree, that is, in 0,1,2,...,l a total of l+1 positions have l+1 tree.
Now to remove some trees, the interval of the removed tree is represented by a pair of numbers, such as 100 200 to remove all trees from 100 to 200 (including the endpoints).
There may be an M (1<=m<=100) interval, and there may be overlapping between intervals. The number of trees remaining after the tree is now required to remove all intervals.
-
Input:
-
Two integer L (1<=l<=10000) and M (1<=m<=100).
Next there are M-group integers, each with a pair of numbers.
-
Output:
-
There may be multiple sets of input data, and for each set of input data, a number is output that represents the number of trees left after the tree has been removed from all intervals.
-
Sample input:
-
500 3100 200150) 300470 471
-
Sample output:
-
298
#include <stdio.h> #include <string.h>int a[10001];int main (int argc, char *argv[]) { int l,m; int start,end; while (~SCANF ("%d%d", &l,&m)) { memset (a,0,sizeof (a)); for (int i=0;i<m;++i) { scanf ("%d%d", &start,&end); for (int i=start;i<=end;++i) a[i]=1; } int ans=0; for (int i=0;i<=l;++i) if (a[i]==0) ans++; printf ("%d\n", ans); } return 0;}
Nine degrees OJ 1088 remaining trees