Tree out of school

Source: Internet
Author: User

Tag: Code rip coordinate, CNT stdio. h ESC des, contains output

There is a row of trees on the road with a length of L outside the gate of a school. The interval between every two adjacent trees is 1 meter. We can regard the road as a number axis, where one end of the road is 0 and the other is L. Each integer point on the number axis is 0, 1, 2 ,......, L. There is a tree. There are some areas on the road to build a subway. These regions are expressed by their starting and ending points on the number axis. It is known that the coordinates of the starting and ending points of any region are integers, and the areas may overlap. Now we need to remove the trees (including the two trees at the region endpoint) in these regions. Your task is to calculate the number of trees on the road after all these trees are removed.

Input

The first line of the input has two integers, L (1 <= L <= 10000) and M (1 <= m <= 100). l represents the length of the road, M indicates the number of regions. L and M are separated by a space. Each row of the next M line contains two different integers separated by a space, representing the coordinates of the start and end points of a region.

Output

The output includes a row. This row contains only one integer, indicating the number of remaining trees on the road.

Sample Input
500 3150 300100 200470 471
Sample output
298
#include<stdio.h>int main(){    int l,m,start,end,sum,i,a[10001]={0};    scanf("%d%d",&l,&m);    while(m--)    {        scanf("%d%d",&start,&end);        for(i=start;i<=end;i++)        {            a[i]=1;        }    }    sum=0;    for(i=0;i<=l;i++)    {        if(a[i]==0)        {            sum++;        }    }    printf("%d\n",sum);    return 0;}

 

Tree out of school

Related Article

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.