A Mindbending Scenario
Input File: bendin.txt
Output File: bendout.txt
Time Limit: 0.05 seconds
Output File: bendout.txt
Time Limit: 0.05 seconds
Imagine a universe far different to the one we know. One where where people can walk through walls, where politicians don't lie, where the rules of physics itself are bent on a daily basis. Imagine how strange it would be to land in that universe, having to adjust to entirely new laws of reality, and having to integrate yourself into sentient cultures far beyond human comprehension.
Now, imagine that everything in this universe was suddenly destroyed in a cataclysmic explosion, leaving nothing but two rectangles on an endless plane. These two rectangles have their corners at integer co-ordinates (rational numbers having been destroyed). Your task is to discover the total area of the plane which is covered by these rectangles.
Beware! Some parts of the plane may be covered by both rectangles. If you merely add the individual areas together, you are surely doomed to incorrect answers!
Input
The input file will consist of two lines. Each line will be of the form x1 y1 x2 y2, describing the bottom-left and top-right corners of one rectangle. You are guaranteed that 0 <= x1 < x2 <= 10,000, and 0 <= y1 < y2 <= 10,000. (That is, each rectangle is at least one unit square in size.)
Output
Your output file should consist of a single integer: the total area covered by rectangles. (Remember - the rectangles may overlap!)
Please check on the python code by clicking the link below: Mind bending problem python code
You may get the original question from Mind bending problem question
No comments:
Post a Comment