This page is still under construction.

Parts of this page are still being built. What you see may change.

Atlantis

Interview

Time limit1sMemory limit128 MB

Summary
Given up to 100 axis-aligned rectangles, compute the area of their union and print it with two decimals.
Level

Medium7 of 10

Topics
Geometry, Segment tree, Prefix sum, Sorting
Solved
No attempts yet

Problem

Several ancient Greek texts contain descriptions of the fabled island of Atlantis. Some of these texts even include maps of parts of the island, but unfortunately these maps describe different regions of Atlantis. Your friend Bill needs to know the total area for which maps exist. You have volunteered to write a program that computes this quantity.

Input

The input consists of several test cases. Each test case begins with a line containing a single integer nn (1≤n≤1001 \le n \le 100), the number of available maps. Each of the following nn lines describes one map with four numbers x1x_1, y1y_1, x2x_2, y2y_2 (0≤x1<x2≤1000000 \le x_1 < x_2 \le 100000; 0≤y1<y2≤1000000 \le y_1 < y_2 \le 100000), not necessarily integers. The pair (x1,y1)(x_1, y_1) is the top-left corner and (x2,y2)(x_2, y_2) is the bottom-right corner of the mapped rectangular area.

The input is terminated by a line containing a single 00, which must not be processed.

Output

For each test case, print two lines. The first line must be Test case #k, where kk is the number of the test case (starting from 11). The second line must be Total explored area: a, where aa is the total explored area — that is, the area of the union of all rectangles in the test case — printed with exactly two digits after the decimal point.

Print a single blank line between consecutive test cases.

Examples3

  1. Example 1

    Input
    2
    10 10 20 20
    15 15 25 25.5
    0
    
    Expected output
    Test case #1
    Total explored area: 180.00
    
  2. Example 2

    Input
    1
    0 0 100 100
    0
    
    Expected output
    Test case #1
    Total explored area: 10000.00
    
  3. Example 3

    Input
    1
    0 0 5 5
    2
    0 0 10 10
    5 5 15 15
    0
    
    Expected output
    Test case #1
    Total explored area: 25.00
    
    Test case #2
    Total explored area: 175.00