Question: How many posters can be viewed in the end.
Question: Recently I want to write a question about rectangular cutting. Of course, this question is not very suitable, but I can pass it.
[Cpp]
# Include <stdio. h>
# Include <stdlib. h>
# Include <string. h>
# Include <string>
# Include <queue>
# Include <algorithm>
# Include <vector>
# Include <stack>
# Include <list>
# Include <iostream>
# Include <map>
# Include <math. h>
Using namespace std;
# Define inf 0x3f3f3f
# Define uint unsigned _ int64
# Define M 1000000
Struct node
{
Int p1, p2, co;
} A [M], now;
Int used [10100], total;
Int judge (node a, node B)
{
If (a. p2 <B. p1 | a. p1> B. p2)
Return 0;
Else return 1;
}
Void cut (node tmp)
{
Int k1, k2;
K1 = max (tmp. p1, now. p1 );
K2 = min (tmp. p2, now. p2 );
If (tmp. p1 <k1)
{
A [++ total] = tmp;
A [total]. p2 = k1-1;
}
If (tmp. p2> k2)
{
A [++ total] = tmp;
A [total]. p1 = k2 + 1;
}
}
Int main ()
{
Int t, I, j, l, r, n;
Scanf ("% d", & t );
While (t --)
{
Scanf ("% d", & n );
Total = 0;
For (I = 1; I <= n; I ++)
{
Scanf ("% d", & l, & r );
Now. p1 = l; now. p2 = r; now. co = I;
For (j = total; j> = 1; j --)
{
If (judge (now, a [j])
{
Cut (a [j]);
A [j] = a [total --];
}
}
A [++ total] = now;
}
Memset (used, 0, sizeof (used ));
Int num = 0;
For (I = 1; I <= total; I ++)
{
If (! Used [a [I]. co])
{
Used [a [I]. co] = 1;
Num ++;
}
}
Printf ("% d \ n", num );
}
}