Question: C . Rectangle Merging time limit per test: 1 second memory limit per test: 2 5 6 megabytes input: standard input output: standard output You
C Rectangle Merging
time limit per test: second
memory limit per test: megabytes
input: standard input
output: standard output
You are given a rectangles. In the first second, only the first rectangle of size ax by is considered. Then, on the ith second, a rectangle of size ax by is attached to one of the sides of the current rectangle without overlapping, so that their union remains a rectangle.
For this, the current rectangle and the rectangle of size a x by must be attached to each other by an equal side. The rectangle could be rotated by and attached to any side of the current rectangle if it had an equal side to it
Based on the information about the sizes of all a rectangles, determine if they can all be merged in such order, and if yes, what possible rectangles could result in the end.
Input
The first line of input contains a single number the number of rectangles n
In the ith of the following lines, two integers a and by are given, separated by a space the sizes of the ith rectangle a b Note that the sizes of the rectangles may not fit into a bit Integer type int
Output
In the first line, output a single integer k the number of possible size variations of the final rectangle. If it is not possible
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
