1.


/**
* Angewandte Mathematik, SS11
* Problem: 591 - Box of Bricks
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=7&page=show_problem&problem=532
*
* @author Marco Wolff
* @author Christian Weber
* @author Christoph Waldleitner
* @version 1.0, 10/23/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.152
*/

import java.io.*;
import java.util.StringTokenizer;
public class Main
{
public static void main(String[] args) throws Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String out ="";
int line = 0;
while (true)
{
StringTokenizer tk = new StringTokenizer(br.readLine());
int counter = Integer.parseInt(tk.nextToken());
if(counter==0)
break;
tk = new StringTokenizer(br.readLine());
int[] num = new int[counter];
int sum = 0;
int moves = 0;
for(int i=0;i<counter;i++)
{
int tmp = Integer.parseInt(tk.nextToken());
sum += tmp;
num[i]=tmp;
}
for(int i=0;i<counter;i++)
{
if(num[i]>(sum/counter))
{
moves+=(num[i]-(sum/counter));
}
}
line++;
System.out.println("Set #"+line);
System.out.println("The minimum number of moves is "+moves+"."+"\n");
}
System.exit(0);
}

}

2.

/**
* Angewandte Mathematik, SS11
* Problem: 591 Box of Brix
* Link: http://uva.onlinejudge.org/external/5/591.pdf
*
* @author Unverzart Michael
* @author Wurth Manuel
* @version 1.0, 19/04/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.108
*/

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;


public class Main {
public static void main(String[] args) throws Exception{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String inputLine="";
int sum=0;
int counter=1;
int avg = 0;
int moves = 0;
int tower = 0;
while((inputLine = reader.readLine())!=null)
{
if(inputLine.equals("0")) break;
int n = new Integer(inputLine);

String tmp = reader.readLine();
StringTokenizer st0 = new StringTokenizer(tmp);
StringTokenizer st1 = new StringTokenizer(tmp);
for(int i=1;i<=n;i++)
{
sum+=Integer.valueOf(st0.nextToken());
}
avg=sum/n;
for(int i=1;i<=n;i++)
{
if((tower = Integer.valueOf(st1.nextToken()))>avg) moves += tower-avg;
}
System.out.println("Set #"+counter);
System.out.println("The minimum number of moves is "+moves+".");
System.out.println("");
counter++;
avg=moves=tower=sum=0;
}
}
}

3.

/**
 * Angewandte Mathematik, SS11
 * Problem: 591 Box of Bricks
 * Link:
http://uva.onlinejudge.org/external/3/374.pdf
 *
 * @author Westerfield, Christopher


 * @author Gent Selmanaj
 * @author Marco Schuster
 * @version 1.0, 04/19/2011
 *
 * Method : Ad-Hoc
 * Status : Accepted
 * Runtime: 0.140
 */

import java.util.*;

class Main{
    public static void main(String... args){


        Scanner in = new Scanner(System.in);
        int[] heights;              //Array Welches die Höhen beinhaltet
        int input;                  //inputline
        int values;                 //anzahl der werte(Stapel)


        int cases=0;                //nummer des Testfalls

        while(in.hasNextInt()){
            input=in.nextInt();
            if (input==0){break;}
            //Alle werte einlesen und die wandhöhe bestimmen


            cases++;
            values=input;
            heights = new int[values];

            int wallheight=0;
            for (int i=0; i<values;i++){
                heights[i]=in.nextInt();


                wallheight+=heights[i];
            }
            wallheight=wallheight/values;

            //berechnung der anzahl der züge
            int moves=0;
            for (int i=0;i<heights.length;i++){


                moves+=Math.abs(heights[i]-wallheight);
            }
            moves/=2;
            System.out.println("Set #" + cases);
            System.out.println("The minimum number of moves is " + moves + ".\n");


        }
    }
}

4.

package sem2.am.boxofbricks;

/**
* Angewandte Mathematik, SS11
* Problem: 591 - Box of Bricks
* Link: http://uva.onlinejudge.org/external/5/591.pdf
*
* @author Florian Stein
* @author Franz Sommer
* @version 1.0, 05/01/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.192
*/

import java.util.*;

public class Main {

public static void main(String... args) {

int test = 0;
List<Integer> bricks = new ArrayList<Integer>();
int numberOfBricks;

Scanner sc = new Scanner(System.in);

while (sc.hasNext()) {

// zuruecksetzen
bricks = new ArrayList<Integer>();
int middleBrickHeight = 0;
int moves = 0;

// anzahl der tuerme einlesen
numberOfBricks = sc.nextInt();

if (numberOfBricks == 0) {
break;
}

// testset erhoehen
test++;

// nimmt alle tuerme auf
for (int i = 0; i < numberOfBricks; i++) {
// fuegt sie zur liste hinzu
bricks.add(sc.nextInt());
// zusammenrechnen um durchschnittshoehe der tuerme zu bekommen
middleBrickHeight = middleBrickHeight + bricks.get(i);
}

// durchschnittshoehe berechnen
middleBrickHeight = middleBrickHeight / numberOfBricks;

// die benoetigten zuege berechnen
for (int i = 0; i < bricks.size(); i++) {
moves = moves + Math.abs(bricks.get(i) - middleBrickHeight);
}
// da 2 mal gerechnet, durch 2 teilen
moves = moves / 2;

// ausgabe
System.out.println("Set #" + test);
System.out.println("The minimum number of moves is " + moves + ".");
System.out.println();
}
}

}

5.

/**
* Angewandte Mathematik, SS11
* Problem: 591 - Box of Bricks
* Link: http://uva.onlinejudge.org/external/5/591.pdf
* @author Georg Weber
* @author Daniel Brielbeck
* @version 1.0, 04/19/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.176
*/
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t;
int i = 1;
while ((t = in.nextInt()) != 0) {
//AVG ermitteln
int[] w = new int[t];
int avg = 0;
for (int z=0;z<t;z++){
w[z]=in.nextInt();
avg += w[z];
}
avg /= w.length;
//Zuege bestimmen
int zuege = 0;
for (int n : w) {
if (n > avg)
zuege += n - avg;
}
System.out.println("Set #" + i++);
System.out.println("The minimum number of moves is " + zuege + ".");
System.out.println("");
}
}
}

--------------------------------------------------------------------------
1.

/*
* ACM Contest training
* Problem: 591 Box of Bricks
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=7&problem=532
*
* @author Christoph Goettschkes
* @version 1.0, 10/20/2010
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.096
*/

import java.io.*;
import java.util.StringTokenizer;

class Main
{
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

String line = reader.readLine();
int setCounter = 1;

while(Integer.parseInt(line) != 0) {
int width = Integer.parseInt(line);
line = reader.readLine();

int[] bricks = new int[width];
StringTokenizer tokenizer = new StringTokenizer(line);

for (int i = 0; i < width; i++) {
bricks[i] = Integer.parseInt(tokenizer.nextToken());
}

int height = 0;
for (int i : bricks)
height += i;
height /= width;

int moves = 0;

for (int i : bricks)
if (i > height)
moves += i - height;

System.out.println("Set #" + setCounter);
System.out.println("The minimum number of moves is " + moves + ".");
System.out.println();

if (!reader.ready())
break;
line = reader.readLine();
setCounter++;
}
}
}



2.


/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS10
* Problem: 591 Box of Bricks
*
* @author Robert Reichart
*
* Status : Accepted
* Runtime: 0.184
*/

import java.util.*;

class Main{
public static void main(String... args){
Scanner in = new Scanner(System.in);
int[] heights; //Array Welches die Höhen beinhaltet
int input; //inputline
int values; //anzahl der werte(Stapel)
int cases=0; //nummer des Testfalls

while(in.hasNextInt()){
input=in.nextInt();
if (input==0){break;}
//Alle werte einlesen und die wandhöhe bestimmen
cases++;
values=input;
heights = new int[values];

int wallheight=0;
for (int i=0; i<values;i++){
heights[i]=in.nextInt();
wallheight+=heights[i];
}
wallheight=wallheight/values;

//berechnung der anzahl der züge
int moves=0;
for (int i=0;i<heights.length;i++){
moves+=Math.abs(heights[i]-wallheight);
}
moves/=2;
System.out.println("Set #" + cases);
System.out.println("The minimum number of moves is " + moves + ".\n");
}
}
}