-
Notifications
You must be signed in to change notification settings - Fork 0
/
10020.c
55 lines (55 loc) · 975 Bytes
/
10020.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include<stdio.h>
#include<string.h>
struct area
{
int x,y;
};
struct area data[100100];
struct area stack[100100];
int m;
int l;
int cmp(const void *a,const void *b)
{
return ((struct area *)a)->x-((struct area *)b)->x;
}
int sum;
void solve_it_fuck(int start,int lt)
{
if (start>=m) return ;
if (data[lt].x>start) {sum=0;return ;}
int i;
int max=data[lt].y,j=lt;
for (i=lt;data[i].x<=start && i<l;i++)
if (data[i].y>max) {max=data[i].y;j=i;}
stack[sum++]=data[j];
solve_it_fuck(data[j].y,i);
}
main()
{
int T;
int N,i,j,k;
scanf("%d",&T);
while (T--)
{
scanf("%d",&m);
l=0;
while (scanf("%d%d",&i,&j))
{
if (i==j && j==0) break;
if (j<=0 || i>=m) continue;
data[l].x=i;
data[l].y=j;
l++;
}
qsort(data,l,sizeof(struct area),cmp);
sum=0;
if (data[0].x>0) sum=0;
else
if (l) solve_it_fuck(0,0);
printf("%d\n",sum);
for (i=0;i<sum;i++)
printf("%d %d\n",stack[i].x,stack[i].y);
if (T) putchar('\n');
}
return 0;
}