import java.io.*; import java.util.*; import java.awt.geom.*; /** * Solution to Walls. * * @author vanb */ public class walls { public Scanner sc; public PrintStream ps; public static final int MAX = 37; // Number of points public int n; // The Plane public boolean plane[][] = new boolean[MAX][MAX]; // Has an x wall been placed here? (Only odd indices will be used) public boolean used[] = new boolean[MAX]; // Is there a y value in our past? public int ypast[] = new int[MAX]; // Is there an x coordinate here? public boolean xval[] = new boolean[MAX]; // Is there a y coordinate here? public boolean yval[] = new boolean[MAX]; // Is there a y wall here? public boolean ywall[] = new boolean[MAX]; // Is it useful to put an x wall here? public boolean useful[] = new boolean[37]; // Current number of walls used, and best. public int wallsplaced, best; /** * Place a wall at a given x value. * If all x walls are placed, count the number of y walls needed. * * @param where x value to place a wall */ public void placewall( int where ) { // Are all x walls placed? if( where<0 ) { // Remember this, so we can restore it later int wp = wallsplaced; // Then look to see where we need y walls. boolean viable = true; // We'll divide the space up into bands, where the // bands are separated by the x walls. // ypast will be indexed by band, not by x! Arrays.fill( ypast, -1 ); // k is the number of the current band int k=0; Arrays.fill( ywall, false ); // Go through every point in the plane for( int y=0; y0 && ypast[k]>=0 && !ywall[y-1]) { // Then we need to build a y wall here // We also need to do something with the ypast array for( int i=0; i