UVA 1617 Laptop

Source: Internet
Author: User

Test instructions

There are n lines of length 1, which determine their starting point and must be integers so that the section I line is between [Ri,di]. Minimum value of the last output void

Analysis:

The order of the original data is sorted by the right endpoint sort, the right endpoint is the same, and then the left endpoint is sorted. Then the far left begins to traverse the segment, judging whether the first right endpoint is less than the second left end, and if it is less than, there must be a gap in the middle and a mark plus 1.

Code:

  

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace Std;
struct Node
{
int l,r;
};
Node node[100010];
int cnt=0;
int n;
BOOL CMP (Node A,node B)
{
if (A.R==B.R)
Return a.l<b.l;
Else
Return a.r<b.r;
}
int main ()
{
int t;
scanf ("%d", &t);
while (t--)
{
scanf ("%d", &n);
int i;
for (i=0;i<n;i++)
scanf ("%d%d", &AMP;NODE[I].L,&AMP;NODE[I].R);
Sort (node,node+n,cmp);
cnt=0;
int R1=NODE[0].R;
for (i=1;i<n;i++)
{
if (NODE[I].R!=R1)
{
if (R1&LT;NODE[I].L)
{
cnt++;
R1=NODE[I].R;
}
Else
{
r1++;
}
}
}
printf ("%d\n", CNT);
}
}

UVA 1617 Laptop

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.