-
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
-
Source:
-
2011, Tsinghua University computer Research Life Test real problem
-
Answering:
-
problem solving problems? to discuss the subject of discussion please visit: http://t.jobdu.com/thread-7811-1-1.html
#include <stdio.h> #include <string.h> int main () { int l,m; int start,end; int I,j,ans; int a[10001]; while (scanf ("%d%d", &l,&m)!=eof) { memset (a,0,sizeof (a)); for (I=0;i<m;++i) { scanf ("%d%d", &start,&end); for (J=START;J<=END;++J) a[j]=1; } ans=0; for (I=0;i<=l;++i) { if (a[i]==0) ans++; } printf ("%d\n", ans); } return 0; }/************************************************************** problem:1088 user:vhreal Language:c result:accepted time:50 ms memory:912 kb********************************************** ******************/
Nine degrees oj-topic 1088: The remaining trees