当前位置:网站首页>P1047 [NOIP2005 普及组 T2] 校门外的树
P1047 [NOIP2005 普及组 T2] 校门外的树
2022-07-25 07:36:00 【hnjzsyjyj】
【题目来源】
https://www.luogu.com.cn/problem/P1047
https://www.acwing.com/problem/content/description/424/
【题目描述】
某校大门外长度为 L 的马路上有一排树,每两棵相邻的树之间的间隔都是 1 米。
我们可以把马路看成一个数轴,马路的一端在数轴 0 的位置,另一端在 L 的位置;数轴上的每个整数点,即 0,1,2,……,L,都种有一棵树。
由于马路上有一些区域要用来建地铁。
这些区域用它们在数轴上的起始点和终止点表示。
已知任一区域的起始点和终止点的坐标都是整数,区域之间可能有重合的部分。
现在要把这些区域中的树(包括区域端点处的两棵树)移走。
你的任务是计算将这些树都移走后,马路上还有多少棵树。
【输入格式】
输入文件的第一行有两个整数 L 和 M。L 代表马路的长度,M 代表区域的数目,L 和 M 之间用一个空格隔开。
接下来的 M 行每行包含两个不同的整数 u,v,用一个空格隔开,表示一个区域的起始点和终止点的坐标。
【输出格式】
输出文件包括一行,这一行只包含一个整数,表示马路上剩余的树的数目。
【数据范围】
对于 20% 的数据,保证区域之间没有重合的部分。
对于 100% 的数据,保证1≤L≤10000,1≤M≤100,0≤u≤v≤L。
【算法代码】
#include <bits/stdc++.h>
using namespace std;
const int maxn=10005;
int L,M;
int f[maxn];
int main() {
scanf("%d%d",&L,&M);
while(M--) {
int le,ri;
scanf("%d%d",&le,&ri);
for(int i=le; i<=ri; i++) f[i]=1;
}
int ans=0;
for(int i=0; i<=L; i++){
if(f[i]==0) ans++;
}
printf("%d\n",ans);
return 0;
}
/*
in:
500 3
150 300
100 200
470 471
out:
298
*/
【参考文献】
https://www.acwing.com/solution/content/3097/
https://www.luogu.com.cn/problem/solution/P1047
边栏推荐
- 【程序员2公务员】三、资源搜集
- Flinkcdc2.0 uses flinksql to collect MySQL
- [software testing] package resume from these points to improve the pass rate
- How to use network installation to deploy multiple virtual servers in KVM environment
- 做好项目管理的10个关键点和5大措施
- JS note 17: the whole process of jest project configuration of typescript project
- Paddlepaddle 34 adjust the layer structure and forward process of the model (realize the addition, deletion, modification and forward modification of the layer)
- Elasticserach里delete_by_query的机制是什么?
- RPC communication principle and project technology selection
- A fast method of data set enhancement for deep learning
猜你喜欢
![[unity entry program] basic concept trigger](/img/16/cd0f8ae579627fc095935195136729.png)
[unity entry program] basic concept trigger

从ACL 2022 Onsite经历看NLP热点

Analysis of difficulties in diagramscene project
![[unity introduction program] basic concepts -2d rigid body 2D](/img/67/537e9935bb0f2539945032cadcf232.png)
[unity introduction program] basic concepts -2d rigid body 2D

MATLAB自编程系列(1)---角分布函数

【Unity入门计划】界面介绍(1)-Scene视图
![[wechat applet] global style, local style, global configuration](/img/8e/c6241ab0f28e3f468dbfa923b91d20.png)
[wechat applet] global style, local style, global configuration

【微信小程序】全局样式、局部样式、全局配置

cesium简介

一日千里,追风逐月 | 深势科技发布极致加速版分子对接引擎Uni-Docking
随机推荐
【微信小程序】全局样式、局部样式、全局配置
从ACL 2022 Onsite经历看NLP热点
钉钉最新版,怎么清除登录手机号历史记录数据
Load capacity - sorting out the mind map that affects load capacity
Elasticserach里delete_by_query的机制是什么?
Alibaba cloud image address & Netease cloud image
J1 常用的DOS命令(P25)
Offline base tile, which can be used for cesium loading
Growth path - InfoQ video experience notes [easy to understand]
DJI push code (one code for one use, limited time push)
深度学习训练和测试时出现问题:error: the following arguments are required: --dataroot,解决:训练文件的配置方法和测试文件的配置方法
【Unity入门计划】界面介绍(1)-Scene视图
【程序员2公务员】一、基本认知
【软件测试】包装简历从这几点出发、提升通过率
RPC communication principle and project technology selection
The idea of the regular crawler of the scratch
[programmer 2 Civil Servant] summary of some common problems about system research
Huawei wireless device sta black and white list configuration command
【程序员2公务员】三、资源搜集
Learn no when playing 9 | enterprise knowledge management is so simple because it uses