Poj 2528 Mayor's posters

Source: Internet
Author: User

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 );
}
}


 

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.