import java.io.*; import java.util.*; import java.awt.geom.*; /** * Solution to Unreal Estate. * * @author vanb */ public class realestate_vanb { public Scanner sc; public PrintStream ps; /** * A single coordinate, either x or y. * * @author vanb */ public class Coordinate implements Comparable { /** The coordinate itself */ public double value; /** Is this the low, or the high coordinate? */ public boolean lo; /** Which plot this coordinate is part of */ public Plot plot; /** Index into the y array (unused for x) */ public int index; /** * Create a coordinate. * * @param value Coordinate value * @param lo Is this the low or high coordinate? * @param plot The plot that this coordinate is a part of */ public Coordinate( double value, boolean lo, Plot plot ) { this.value = value; this.lo = lo; this.plot = plot; this.index = -1; } /** * Compare two coordinates by their value. * * @param c Another coordinate * @return -1, 0 or 1, as per usual. */ public int compareTo( Coordinate c ) { return Double.compare( value, c.value ); } /** * Return a pretty string for debugging. * * @return A pretty string */ public String toString() { return "[" + value + "," + lo + "," + index + "]"; } } /** * A plot, recording all 4 coordinates: xlo, ylo, xhi, yhi * * @author vanb */ public class Plot { Coordinate xlo, xhi, ylo, yhi; } /** * Driver. * @throws Exception */ public void doit() throws Exception { sc = new Scanner (System.in); ps = System.out; for(;;) { int n = sc.nextInt(); if( n==0 ) break; // Read in the data, creating arrays of xs and ys Coordinate xs[] = new Coordinate[n+n]; Coordinate ys[] = new Coordinate[n+n]; for( int i=0; i0) heights[i-1] = ys[i].value - lasty; lasty = ys[i].value; } // We're going to go through the area in slices, by x coordinate. // We'll handle overlap by keeping a count of how many plots each height is in. int counts[] = new int[n+n]; // Total height of all plots in a slice double totalheight = 0.0; // This will be our final answer double area = 0.0; // The last x. We'll need this to figure the width of a slice. double lastx = 0.0; for( int i=0; i