Nosy Xiaoming (Nanyang oj51) (tagged array)

Source: Internet
Author: User

Nosy xiaoming time limit:4000Ms | Memory Limit:65535KB Difficulty:2
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. The clever xiaoming did one thing after another, he thought this is very interesting, wants to use the computer to help the construction worker to statistic these trees, now the task has come, calculates to remove these trees all, the road still has how many trees.
Input
The first line is an integer n indicating there are n sets of test data (1<=n<=100)
The first line of each set of test data has two integers: 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.


Output
The
output includes one row, which contains only an integer that represents the number of trees remaining on the road.

Sample input
1500 3150 300100) 200470 471
Sample output
298
Source
Classic
Uploaded by

Hzyqazasdf

#include <stdio.h> #include <string.h>int a[10002];int main () {int test,i,m,n,ans,t,k;scanf ("%d",& Test), while (test--) {scanf ("%d%d", &m,&n), memset (A,0,sizeof (a)), while (n--) {scanf ("%d%d", &t,&k); for (i=t;i<=k;i++)  a[i]=1;} for (i=0,ans=0;i<=m;i++) {if (!a[i])   ans++;    } printf ("%d\n", ans);} return 0;}

Nosy Xiaoming (Nanyang oj51) (tagged array)

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.