Tag: Code rip coordinate, CNT stdio. h ESC des, contains output
There is a row of trees on the road with a length of L outside the gate of a school. The interval between every two adjacent trees is 1 meter. We can regard the road as a number axis, where one end of the road is 0 and the other is L. Each integer point on the number axis is 0, 1, 2 ,......, L. There is a tree. There are some areas on the road to build a subway. These regions are expressed by their starting and ending points on the number axis. It is known that the coordinates of the starting and ending points of any region are integers, and the areas may overlap. Now we need to remove the trees (including the two trees at the region endpoint) in these regions. Your task is to calculate the number of trees on the road after all these trees are removed.
Input
The first line of the input has two integers, L (1 <= L <= 10000) and M (1 <= m <= 100). l represents the length of the road, M indicates the number of regions. L and M are separated by a space. Each row of the next M line contains two different integers separated by a space, representing the coordinates of the start and end points of a region.
Output
The output includes a row. This row contains only one integer, indicating the number of remaining trees on the road.
Sample Input
500 3150 300100 200470 471
Sample output
298
#include<stdio.h>int main(){ int l,m,start,end,sum,i,a[10001]={0}; scanf("%d%d",&l,&m); while(m--) { scanf("%d%d",&start,&end); for(i=start;i<=end;i++) { a[i]=1; } } sum=0; for(i=0;i<=l;i++) { if(a[i]==0) { sum++; } } printf("%d\n",sum); return 0;}
Tree out of school