1-6-06: Trees outside the school gate

Source: Internet
Author: User

Describe

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 integer l (1 <= L <= 10000) and M (1 <= m <=), L represents 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.

For 20% of the data, there is no overlap between the regions;
For other data, there is a overlap between the regions.
Output
includes a row that contains only an integer that represents the number of trees remaining on the road.
Sample input
500 3150 300100) 200470 471
Sample output
298
1#include <stdio.h>2 intMain ()3 {4     inta[10001]={0};5     intL,m,l1,l2,c=0;6scanf"%d%d",&l,&M);7      for(intI=1; i<=m;i++)8     {9scanf"%d%d",&l1,&L2);Ten          for(intt=l1;t<=l2;t++) Onea[t]=1; A     } -      for(intI=0; i<=l;i++) -         if(a[i]==0) C + +; theprintf"%d\n", c); -     return 0; -}

1-6-06: Trees outside the school gate

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.