POJ 2665 Trees 水
2015-08-22 10:29
155 查看
Trees
Description
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.
Input
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
Output the number of trees left in one line for each test case.
Sample Input
Sample Output
Source
Beijing 2005 Preliminary
水的毫无人性!!!
ACcode:
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 10123 | Accepted: 6650 |
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.
Input
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
Output the number of trees left in one line for each test case.
Sample Input
300 1 100 200 500 2 100 200 201 300 0 0
Sample Output
200 300
Source
Beijing 2005 Preliminary
水的毫无人性!!!
ACcode:
#include <map> #include <queue> #include <cmath> #include <cstdio> #include <cstring> #include <stdlib.h> #include <iostream> #include <algorithm> #define maxn 2000+10 using namespace std; int main(){ long long m,n,st,ed,cnt; while(cin>>m>>n&&(m&&n)){ while(n--){ cin>>st>>ed; m=m-(ed-st)-1; } cout<<m+1<<'\12'; } return 0; }
相关文章推荐
- #ifndef 在头文件中的作用
- 【07】 Boost库学习笔记之异步通信(UDP)
- 【08】 Boost库学习笔记之异步通信(Serial)
- 对于多线程访问同一变量是否需要加锁的问题
- Codeforces Round #249 (Div. 2)453C Cardiogram(模拟)
- iOS过场动画调研笔记
- ubuntu 12.04 下搭接Qt 嵌入式开发环境
- Objective-C基础知识点
- ORA-01747: user.table.column, table.column 或列说明无效
- Spring MVC 教程,快速入门,深入分析
- fatal error LNK1281: 无法生成 SAFESEH 映像。
- [网络流24题] 10 餐巾 (线性规划网络优化 ,最小费用最大流)
- POJ 3090 Visible Lattice Points
- 社説 20150822 70年談話質疑 歴史認識の共有進める土台に
- 【05】 Boost库学习笔记之正则表达式(regex)
- 【06】 Boost库学习笔记之异步通信(TCP)
- bootstrap 手机 菜单
- iOS UIControl 几个事件的说明
- poj-1077 八数码 【a*】
- 【03】 Boost库学习笔记之Bind