当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

2665:Trees

题目描述
The road off the east gate of Peking University used to be decorated with a lot of trees. However, because of the construction of a subway, a lot of them are cut down or moved away. Now please help to count how many trees are left.

Let's only consider one side of the road. Assume that trees were planted every 1m (meter) from the beginning of the road. Now some sections of the road are assigned for subway station, crossover or other buildings, so trees in those sections will be moved away or cut down. Your job is to give the number of trees left.

For example, the road is 300m long and trees are planted every 1m from the beginning of the road (0m). That's to say that there used to be 301 trees on the road. Now the section from 100m to 200m is assigned for subway station, so 101 trees need to be moved away and only 200 trees are left.
输入解释
There are several test cases in the input. Each case starts with an integer L (1 <= L < 2000000000) representing the length of the road and M (1 <= M <= 5000) representing the number of sections that are assigned for other use.

The following M lines each describes a section. A line is in such format:

Start End

Here Start and End (0 <= Start <= End <= L) are both non-negative integers representing the start point and the end point of the section. It is confirmed that these sections do not overlap with each other.

A case with L = 0 and M = 0 ends the input.
输出解释
Output the number of trees left in one line for each test case.
输入样例
300 1
100 200
500 2
100 200
201 300
0 0
输出样例
200
300

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-2665

最后修改于 2020-10-29T06:38:37+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 65536