当前位置:网站首页>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公务员】一、基本认知
- 【Unity入门计划】制作我的第一个小游戏
- How does uxdb extract hours, minutes and seconds from date values?
- [pytorch] the most common function of view
- [unity introduction program] basic concept - preform prefab
- 集群聊天服务器:项目问题汇总
- [cloud native] the ribbon is no longer used at the bottom of openfeign, which started in 2020.0.x
- 纳米数据足球数据,足球赛事比分,体育数据api,卡塔尔世界杯
- What are the types of financial products in 2022? Which is suitable for beginners?
- Polling, interrupt, DMA and channel
猜你喜欢

Simulation Implementation of list

How to use network installation to deploy multiple virtual servers in KVM environment

list的模拟实现

【论文笔记】Next-ViT: Next Generation Vision Transformer for Efficient Deployment in Realistic Industrial

Nailing the latest version, how to clear the login phone number history data
![[unity introduction program] basic concepts - 2D collider collider 2D](/img/cf/a546238a5eaf4707006ecf1b7f19c6.png)
[unity introduction program] basic concepts - 2D collider collider 2D

Security compliance, non-stop discounts! High quality travel service, "enjoy the road" for you

Summary of differences between data submission type request payload and form data

Robot framework mobile terminal Automation Test ----- 01 environment installation

Lidar construction map (overlay grid construction map)
随机推荐
【Unity入门计划】基本概念-2D碰撞体Collider 2D
Robot framework mobile terminal Automation Test ----- 01 environment installation
9 best engineering construction project management systems
list的模拟实现
线代(矩阵‘)
Problems during nanodet training: modulenotfounderror: no module named 'nanodet' solution
Simulation Implementation of list
9大最佳工程施工项目管理系统
J1 common DOS commands (P25)
集群聊天服务器:项目问题汇总
[notes] search rotation sort array
RPC communication principle and project technology selection
toolbar的使用
diagramscene工程难点分析
Use cyclegan to train self-made data sets, popular tutorials, and get started quickly
Have you got the advanced usage of pytest?
Robot Framework移动端自动化测试----01环境安装
Talk about programmers learning English again
深度学习训练和测试时出现问题:error: the following arguments are required: --dataroot,解决:训练文件的配置方法和测试文件的配置方法
ACNet:用于图像超分的非对称卷积(附实现code)