Ask a question to Desklib · AI bot

Ask NowBETA

Area of rectangles union.

Added on -2019-09-16

| 1 pages
| 188 words
| 190 views

Trusted by 2+ million users,
1000+ happy students everyday

Area of rectangles union-Given N rectangles with edges parallel to axis, calculate the area of the union of all rectangles.-A rectangle is specified by giving its smallest and largest x- and y-coordinates x1, x2, y1, y2, where x1 < x2 and y1 < y2.-Bottom left corner is at (x1, y1) and the upper right corner at (x2, y2).-The area of this rectangle is given by the formula (x2 – x1)*(y2 – y1)Rectangles may intersect each other or may even be inside each other.-The task is to write a program in Java that reads n rectangles and return the total area.-The complexity should not be O(n2). The format of the input is:-<Number of rectangles>-<x1> <x2><y1>y2>-<x1> <x2><y1>y2>-......Output file should contain 1 number - the resulting area of the rectangles' union

Found this document preview useful?

You are reading a preview
Upload your documents to download
or
Become a Desklib member to get accesss

Students who viewed this