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", &NODE[I].L,&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<NODE[I].L)
{
cnt++;
R1=NODE[I].R;
}
Else
{
r1++;
}
}
}
printf ("%d\n", CNT);
}
}
UVA 1617 Laptop