Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started