-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoj-51-1.c
78 lines (74 loc) · 2.22 KB
/
oj-51-1.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <stdio.h>
int main()
{
freopen("C:\\Users\\Root\\Downloads\\Input.txt", "r", stdin);
int n, l, m;//record == m?
int x1, x2;
int span[100][2];
int i, j, k;
int inclusion;
scanf("%d", &n);
while(n--)
{
scanf("%d %d", &l, &m);
for(i = 0; i < m; i++)
{
inclusion = 0;
scanf("%d %d", &x1, &x2);
for(j = 0; j < i; j++)
{
if(x1 >= span[j][0] && x2 <= span[j][1])
{
inclusion = 1;
printf("1. i = %d, j = %d\n", i, j);
break;
}
else if(x1 < span[j][0] && x2 > span[j][1])
{
while(j < i)
{
span[j][0] = span[j + 1][0];
span[j][1] = span[j + 1][1];
j++;
}
//span[j][0] = x1;
//span[j][1] = x2;
inclusion = 1;
j = 0;
printf("2. i = %d, j = %d\n", i, j);
}
else if(x1 < span[j][0] && x2 >= span[j][0] && x2 < span[j][1])
{
x2 = span[j][0] - 1;
}
else if(x1 >= span[j][0] && x1 <= span[j][1] && x2 > span[j][1])
{
x1 = span[j][1] + 1;
}
printf("i = %d, j = %d, x1 = %d, x2 = %d\n\n", i, j, x1, x2);
}//end for 'j' in 'i'
if(inclusion != 1)
{
printf("i = %d\n", i);
printf("i = %d, x1 = %d, x2 = %d\n\n", i, x1, x2);
span[i][0] = x1;
span[i][1] = x2;
}
else
{
i--;
m--;
}
}//end for 'i' in 'm'
l++;
for(i = 0; i < m; i++)
{
//printf("x1 = %d, x2 = %d\t", span[i][0], span[i][1]);
//printf("---%d\n", span[i][1] - span[i][0] + 1);
l-=(span[i][1] - span[i][0] + 1);
}
printf("%d\n", l);
printf("\n-----------------------------\n");
}
return 0;
}