Nine degrees oj-topic 1088: The remaining trees

Source: Internet
Author: User

Title Description:

There is a length of the whole number of L (1<=l<=10000) of the road, you can imagine the length of the axis of a line of L, the starting point is the origin of the coordinates, at each integer coordinate point there is a tree, that is, in 0,1,2,...,l a total of l+1 positions have l+1 tree.
Now to remove some trees, the interval of the removed tree is represented by a pair of numbers, such as 100 200 to remove all trees from 100 to 200 (including the endpoints).
There may be an M (1<=m<=100) interval, and there may be overlapping between intervals. The number of trees remaining after the tree is now required to remove all intervals.

Input:

Two integer L (1<=l<=10000) and M (1<=m<=100).
Next there are M-group integers, each with a pair of numbers.

Output:

There may be multiple sets of input data, and for each set of input data, a number is output that represents the number of trees left after the tree has been removed from all intervals.

Sample input:
500 3100 200150) 300470 471
Sample output:
298
Source:
2011, Tsinghua University computer Research Life Test real problem
Answering:
problem solving problems? to discuss the subject of discussion please visit: http://t.jobdu.com/thread-7811-1-1.html

#include <stdio.h> #include <string.h> int main () {    int l,m;    int start,end;    int I,j,ans;    int a[10001];     while (scanf ("%d%d", &l,&m)!=eof)     {         memset (a,0,sizeof (a));        for (I=0;i<m;++i)        {             scanf ("%d%d", &start,&end);            for (J=START;J<=END;++J)                a[j]=1;         }                 ans=0;        for (I=0;i<=l;++i)        {            if (a[i]==0)                ans++;        }                 printf ("%d\n", ans);    }         return 0; }/**************************************************************    problem:1088    user:vhreal    Language:c    result:accepted    time:50 ms    memory:912 kb********************************************** ******************/


Nine degrees oj-topic 1088: The remaining trees

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.