A tree outside the gate of NOIP200502

Source: Internet
Author: User

question description
  & nbsp A school gate outside the length of the road is a row of trees, every two adjacent trees between the interval is 1 meters. We can think of the road as a axis, one end of the road in the position of the axis 0, the other end in the position of L; each integral point on the axis, namely 0,1,2,......,l, is planted with a tree. There are some areas on the road to be used to build subways. These regions are represented by their starting and ending points on the axis. The coordinates of the starting and ending points of any given area are integers, and there may be overlapping parts between regions. Now the trees in these areas (including the two trees at the end of the area) are removed. Your task is to calculate how many trees there are on the road after the trees have been removed.
input
The first line has two integers l and m,l represent the length of the road, M represents the number of areas, and L and M are separated by a space. The next M-line contains two different integers, separated by a space, representing the coordinates of the starting and ending points of an area.
output
includes a row that contains only an integer that represents the number of trees remaining on the road.
Input Example
500 3
150 300
100 20 0
470 471
Output sample
298
Additional instructions
data range: 1<=l<=10000,1<=m<=100.
 
The main thing is to define an array, which is recorded within the range of the subway that is not to be built. (recorded with 1 and 0)
1#include <iostream>2 3 using namespacestd;4 5 intMain ()6 {7     intl,m,i,b,c,j,ans=0;8     inta[10001]={0};9Cin>>l>>m;Ten      for(i=1; i<=m;i++) One     { ACin>>b>>C; -          for(j=b;j<=c;j++) a[j]=1; -     } the      for(i=0; i<=l;i++) -         if(a[i]==0) ans++; -cout<<ans; -     return 0; +}
a tree outside the gate

A tree outside the gate of NOIP200502

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.