POJ 2665 Trees 水
来源:互联网 发布:寻仙3100端口 编辑:程序博客网 时间:2024/05/15 12:22
Trees
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 10123 Accepted: 6650
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.
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.
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 1100 200500 2100 200201 3000 0
Sample Output
200300
Source
Beijing 2005 Preliminary
水的毫无人性!!!
ACcode:
水的毫无人性!!!
ACcode:
#include <map>#include <queue>#include <cmath>#include <cstdio>#include <cstring>#include <stdlib.h>#include <iostream>#include <algorithm>#define maxn 2000+10using 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;}
0 0
- POJ 2665 Trees 水
- POJ 2665 Trees(水~)
- POJ 2665 Trees
- POJ 2665 Trees
- poj 2665 Trees
- POJ 2665 Trees G++
- POJ 2665 Trees(水题)
- POJ 2665 Trees(我的水题之路——移树,POJ100题啦!)
- POJ 1610 Quad Trees
- 【POJ 1105 S-Trees】
- POJ - 2029 Get Many Persimmon Trees(暴力水题)
- POJ 1105 S-Trees (模拟)
- POJ 2029 Get Many Persimmon Trees 二维树状数组(水)
- poj 1095--Trees Made to Order
- poj 1095 Trees Made to Order
- POJ 2029 Get Many Persimmon Trees
- Poj 2029 Get Many Persimmon Trees
- POJ 1095 Trees Made to Order 递归
- 【04】 Boost库学习笔记之线程(thread)
- ORA-01747: user.table.column, table.column 或列说明无效
- Android项目Tab类型主界面大总结 Fragment+TabPageIndicator+ViewPager
- 【05】 Boost库学习笔记之正则表达式(regex)
- POJ 3090 Visible Lattice Points
- POJ 2665 Trees 水
- 社説 20150822 70年談話質疑 歴史認識の共有進める土台に
- Objective-C基础知识点
- Matlab中数据的标准化处理
- 【06】 Boost库学习笔记之异步通信(TCP)
- 对于多线程访问同一变量是否需要加锁的问题
- cortex-m3非对齐访问引发HardFault
- VS2012安装时启动界面一闪而过问题解决办法
- 【07】 Boost库学习笔记之异步通信(UDP)