当前位置:网站首页>P1047 [noip2005 popularization group t2] tree outside the school gate
P1047 [noip2005 popularization group t2] tree outside the school gate
2022-07-25 07:40:00 【hnjzsyjyj】
【 Title source 】
https://www.luogu.com.cn/problem/P1047
https://www.acwing.com/problem/content/description/424/
【 Title Description 】
The length of a school gate is L There are a row of trees on the road , The interval between every two adjacent trees is 1 rice .
We can think of the road as a number axis , One end of the road is on the number axis 0 The location of , In the other end L The location of ; Every integer point on the number axis , namely 0,1,2,……,L, They all have a tree .
Because there are some areas on the road that will be used to build subways .
These areas are represented by their starting and ending points on the number axis .
It is known that the coordinates of the starting point and the ending point of any area are integers , There may be overlaps between areas .
Now let's put the trees in these areas ( Includes two trees at the end of the area ) Removal .
Your task is to calculate how to move all these trees away , How many trees are there on the road .
【 Input format 】
The first line of the input file has two integers L and M.L Represents the length of the road ,M Represents the number of regions ,L and M Separated by a space .
Next M Each line contains two different integers u,v, Separated by a space , Represents the coordinates of the starting point and the ending point of an area .
【 Output format 】
The output file contains one line , This line contains only one integer , Represents the number of trees remaining on the road .
【 Data range 】
about 20% The data of , Ensure that there is no overlap between areas .
about 100% The data of , Guarantee 1≤L≤10000,1≤M≤100,0≤u≤v≤L.
【 Algorithm code 】
#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
*/
【 reference 】
https://www.acwing.com/solution/content/3097/
https://www.luogu.com.cn/problem/solution/P1047
边栏推荐
- 12 combination methods and risk interpretation of database architecture optimization (books available)
- 关于GBase 自动关闭连接问题
- MATLAB自编程系列(1)---角分布函数
- 【论文笔记】EFFICIENT CNN ARCHITECTURE DESIGN GUIDED BY VISUALIZATION
- Analysis of common classes of Servlet
- P1086 [NOIP2004 普及组第二题] 花生采摘
- Practical operation: elegant downtime under large-scale micro service architecture
- 【程序员2公务员】三、资源搜集
- [unity entry plan] interface Introduction (1) -scene view
- Use cyclegan to train self-made data sets, popular tutorials, and get started quickly
猜你喜欢

Today in history: Intel was founded; The first photo was posted on the world wide web; EBay spins off PayPal

Oracle19采用自动内存管理,AWR报告显示SGA、PGA设置的过小了?
![[unity entry program] basic concept trigger](/img/16/cd0f8ae579627fc095935195136729.png)
[unity entry program] basic concept trigger
![[paper notes] progressive layered extraction (PLE): a novel multi task learning (MTL) model for personalized](/img/a8/c5d14ec5f4a22f7925c6d7454b5a58.png)
[paper notes] progressive layered extraction (PLE): a novel multi task learning (MTL) model for personalized

深度学习训练和测试时出现问题:error: the following arguments are required: --dataroot,解决:训练文件的配置方法和测试文件的配置方法
![[wechat applet] global style, local style, global configuration](/img/8e/c6241ab0f28e3f468dbfa923b91d20.png)
[wechat applet] global style, local style, global configuration

UNIPRO multi terminal deployment to meet customers' diversified needs
![[unity entry plan] interface Introduction (1) -scene view](/img/88/dee292cb90cd740640018e7260107f.png)
[unity entry plan] interface Introduction (1) -scene view

【论文笔记】Progressive Layered Extraction (PLE): A Novel Multi-Task Learning (MTL) Model for Personalized

华为无线设备配置WPA2-802.1X-AES安全策略
随机推荐
Problems in deep learning training and testing: error: the following arguments are required: --dataroot, solution: the configuration method of training files and test files
Analysis of difficulties in diagramscene project
Beijing internal promotion | Microsoft STCA recruits nlp/ir/dl research interns (remote)
Google Earth engine - Landsat 1985-2020 ecological remote sensing index resi calculation
On the peak night of the 8 Oracle ace gathering, what technology hotspots did you talk about?
Use of toolbar
P1047 [NOIP2005 普及组 T2] 校门外的树
Offline base tile, which can be used for cesium loading
Huawei wireless device sta black and white list configuration command
[pytorch] the most common function of view
Elasticserach里delete_by_query的机制是什么?
3. Promise
How to use network installation to deploy multiple virtual servers in KVM environment
SAP queries open Po (open purchase order)
[unity introduction program] basic concepts GameObject & components
GBase 8a中关于--skip-networking 问题
Teach you to use cann to convert photos into cartoon style
Summary of learning notes of deep learning application development (II)
设计一个有getMin功能的栈
整数a按位取反(~)后的值为-(a+1)