All pastes #1768901 Raw Edit

bblum

public text v1 · immutable
#1768901 ·published 2010-01-28 03:02 UTC
rendered paste body
package edu.cmu.cs211.dynprog;import java.util.List;import edu.cmu.cs211.dynprog.util.Box;public class BoxStacker {	/**	 * Finds the optimal stacking of of the boxes.	 * 	 * @param boxes	 *            The set of boxes eligible to be stacked. This is sorted in	 *            descending order of base area and contains all distinct	 *            orientations.	 * @return The maximum height attainable with such a stack	 * @throws NullPointerException	 *             if boxes is null	 */	public static int stackHeight(List<Box> boxes)	{		int[] foo = new int[boxes.size()];				for (int i = 0; i < boxes.size(); i++)		{			if (i == 0)			{				foo[i] = boxes.get(i).getHeight();			}			else			{				int j = blasphemy(foo, i-1);				//box can fit at optimal point				if ((boxes.get(j).getLength() > boxes.get(i).getLength() &&				     boxes.get(j).getWidth() > boxes.get(i).getWidth()) ||				    (boxes.get(j).getLength() > boxes.get(i).getWidth() &&				     boxes.get(j).getWidth() > boxes.get(i).getLength()))				{					foo[i] = foo[j] + boxes.get(i).getHeight();				}				else				{										int[] bar = new int[i];										for (j = 0; j < i; j++)					{													// box cannot fit on stack at given point						if (!((boxes.get(j).getLength() > boxes.get(i).getLength() &&						     boxes.get(j).getWidth() > boxes.get(i).getWidth()) ||						    (boxes.get(j).getLength() > boxes.get(i).getWidth() &&						      boxes.get(j).getWidth() > boxes.get(i).getLength())))						{							bar[j] = boxes.get(i).getHeight();						}						else						{							bar[j] = foo[j] + boxes.get(i).getHeight();						}					}						foo[i] = madness(bar, i-1);				}			}		}		return madness(foo, boxes.size() - 1);	}		/**	 * Perform a series of operations given an integer array and an integer.	 * Note: The first line is 64 characters, the second line is 32, ...	 * @param OO The first argument given to the function	 * @param O0 The second argument given to the function	 * @return A primitive integer value	 */	private static int blasphemy(int[] OO, int O0)	{		return (O0==((O0^O0)<<(O0)))?(O0&(OO[O0]>>>O0)&OO[O0^O0]+O0):(OO		[O0]>madness(OO,(O0+~(O0^O0))))?		O0:blasphemy(OO,		(O0+~(O0		^O0)		))		;	}	/**	 * Do a bunch of stuff, most likely involving a for loop of some sort.	 * Note: there are exactly 211 characters in this function	 * @param a An array of integer values	 * @param n Another integer value	 * @return A whole number between -2 147,483,648 and 2,147,483,648, inclusive	 * @throws you into a bottomless pit	 */	private static int madness(int[] a, int n)	{		int i,s;i=((n+n)&~(		n+n));for(s=(i^i);!		(s>n);s-=(~((s&(~(i		^i))-(s|((n^i)&~(i^		n))))))){i=(a[s]>i)		?a[s]:i;}return(i>>		(((~(s^i))&(i^s))-(		~((s&i)^(i&s))))<<(		~((~s)|s)-(~(n&(~n)		))))+(i&((s^s)-((((i		&s)|(s^i))|(~i)))));	}		/**	 * Finds a list of Boxes that, stacked in order, are as tall as possible.	 * This method is for extra credit.	 * 	 * @param boxes	 *            The set of boxes eligible to be stacked. This is sorted in	 *            descending order of base area and contains all distinct	 *            orientations.	 * @return A maximal height list of boxes in order from bottom to top.	 * @throws NullPointerException	 *             if boxes is null	 */	public static List<Box> getStack(List<Box> boxes)	{		throw new RuntimeException ("You need to implement this method");	}}