-->
当前位置:首页 > 题库

PROGRAMMING:The tree outside the school gate

Luz5年前 (2021-05-10)题库468
###Task description
There is a row of trees on the L-length road outside the gate of a school, and the interval between each two adjacent trees is 1 meter. We can think of the road as a number axis. One end of the road is at the position of number axis 0, and the other end is at the position of L; Every integer point on the number axis, that is, 0, 1, 2,..., l, has a tree.
Because there are some areas on the road to be used for subway construction. These regions are represented 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 there may be overlapping parts between regions. Now you need to move the trees in these areas (including the two trees at the end of the area). Your task is to calculate how many trees are left on the road after all these trees are removed.
###Input format:
The first line has two integers L (1 < = l < = 10000) and m (1 < = m < = 100). L represents the length of the road, M represents the number of areas, and l and m are separated by a space. The next M lines contain two different integers, separated by a space, indicating the coordinates of the starting and ending points of a region.
For 20% of the data, there is no overlap between regions;
For other data, there is overlap between regions.
###Output format:
Include a row that contains only an integer representing the number of trees remaining on the road.
###Input example:
```in
500 3
150 300
100 200
470 471
```
###Output example:
```out
two hundred and ninety-eight
```
###Title Source
Note: this topic is selected from openjudge website http://noi.openjudge.cn/ch0106/06/ .







answer:If there is no answer, please comment