#P5402. [CTS2019] 无处安放

[CTS2019] 无处安放

Background

In the lonely late night, the hazy moonlight puts a thin veil over everything. You walk along a quiet path, sometimes lowering your head in thought, sometimes gazing at the starry sky. You are accompanied only by loneliness and hesitation. Even if you have a few words, there is no one to talk to. Countless thoughts move with your burning heart, drifting with the wind, with nowhere to be placed.

Problem Description

You have整理 organized nn thoughts. In your heart, each of them is a rectangle rir_i. You want to use a big rectangle RR in your heart to place them, that is, place each rir_i inside RR. To protect these thoughts, their placed positions must not overlap with each other, and their four sides must be parallel or perpendicular to the sides of RR. Two thoughts are considered overlapping if the intersection area of their placed positions is greater than zero.

You have two placing methods:

  1. Place all nn thoughts into RR, and hope to make the area of RR as small as possible.
  2. Fix the size of RR, and hope to place as many thoughts as possible into RR.

Now I already know the thoughts you have organized, and I have chosen the placing method for you. I want to know the best placing plan in your heart. Please tell me.

Input Format

The first line contains two integers type,ntype, n, representing the placing method and the number of thoughts, respectively.

If type=2type = 2, the second line contains two integers W,HW, H, representing the side lengths of RR.

The next nn lines each contain two integers wi,hiw_i, h_i, representing the side lengths of the ii-th thought, i.e., rir_i.

Integers on the same line are separated by a single space.

Output Format

For convenience, if the side lengths of RR are W,HW, H, we view the placing plan as a Cartesian coordinate system (0,0)(W,H)(0, 0)\sim(W, H). Note that for test points with type=2type = 2, you should follow the input and treat it as the coordinate system (0,0)(W,H)(0, 0)\sim(W, H), rather than (0,0)(H,W)(0, 0)\sim(H, W).

Output a total of nn lines. Each line contains one or four integers, describing the placement plan of the ii-th thought, i.e., rir_i.

The first integer on each line is cic_i. Here ci=1c_i = 1 means that rir_i is placed in RR; ci=0c_i = 0 means that rir_i is not placed in RR.

If ci=1c_i = 1, then output three more integers xix_i, yiy_i, dirid_{ir_i}. If diri=0d_{ir_i} = 0, then rir_i is placed within the rectangle (xi,yi)(xi+wi,yi+hi)(x_i, y_i)\sim(x_i + w_i, y_i + h_i); if diri=1d_{ir_i} = 1, then rir_i is placed within the rectangle (xi,yi)(xi+hi,yi+wi)(x_i, y_i)\sim(x_i + h_i, y_i + w_i).

Please make sure your output format is correct, and that ci,diri{0,1}c_i, d_{ir_i} \in \{0, 1\}. For test points with type=1type = 1, all cic_i must be 11.

Integers on the same line should be separated by a single space.

1 3
1 1
1 1
2 1
1 0 0 0
1 0 1 0
1 1 0 1
2 4
2 2
1 1
1 1
2 1
2 1
1 0 0 0
1 0 1 0
1 1 0 1
0

Hint

Scoring

Each test point provides 1010 scoring parameters a1,a2,...,a10a_1, a_2, ..., a_{10}. If a contestant’s output is invalid, the score is zero.

Otherwise, for placing method 11, let valval be the area of RR. If valaival \leq a_i, then you can get ii points. For placing method 22, let valval be the number of thoughts placed into RR. If valaival \geq a_i, then you can get ii points. If multiple scoring conditions are satisfied, the score for the test point is the highest one.

Translated by ChatGPT 5