#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 thoughts. In your heart, each of them is a rectangle . You want to use a big rectangle in your heart to place them, that is, place each inside . 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 . Two thoughts are considered overlapping if the intersection area of their placed positions is greater than zero.
You have two placing methods:
- Place all thoughts into , and hope to make the area of as small as possible.
- Fix the size of , and hope to place as many thoughts as possible into .
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 , representing the placing method and the number of thoughts, respectively.
If , the second line contains two integers , representing the side lengths of .
The next lines each contain two integers , representing the side lengths of the -th thought, i.e., .
Integers on the same line are separated by a single space.
Output Format
For convenience, if the side lengths of are , we view the placing plan as a Cartesian coordinate system . Note that for test points with , you should follow the input and treat it as the coordinate system , rather than .
Output a total of lines. Each line contains one or four integers, describing the placement plan of the -th thought, i.e., .
The first integer on each line is . Here means that is placed in ; means that is not placed in .
If , then output three more integers , , . If , then is placed within the rectangle ; if , then is placed within the rectangle .
Please make sure your output format is correct, and that . For test points with , all must be .
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 scoring parameters . If a contestant’s output is invalid, the score is zero.
Otherwise, for placing method , let be the area of . If , then you can get points. For placing method , let be the number of thoughts placed into . If , then you can get points. If multiple scoring conditions are satisfied, the score for the test point is the highest one.
Translated by ChatGPT 5