Want to try solving this problem? You can submit your code online if you log in or register.
The problems in this set are designed to be more accessible to beginning coders. As a learning aid, walkthroughs discussing how to solve the problems in this set are available by clicking on this link. On completion of this problem set, students should know how to use a programming language to read and write files, perform simple arithmetic calculations, and write conditional (if) statements.
Input File: bendin.txt
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!
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.)
Your output file should consist of a single integer: the total area covered by rectangles. (Remember - the rectangles may overlap!)
1 1 3 4 2 3 6 7
The sample data describes the following two rectangles:
The total area covered by the rectangles is 21 unit squares.
The score for each input file will be 100% if the correct answer is written to the output file and 0% otherwise.
© Australian Mathematics Trust 2001-2023
Page generated: 24 March 2023, 8:40pm AEDT