1. Java, Evgeni Pavlidis


/**
* ACM programming Contest WS 08/09
* UVa Status: accepted
* Run Time: 0.300
* @author Evgeni Pavlidis evgenipavlidis@yahoo.de
*/
import java.util.*;
import java.io.*;

class Main extends Thread{

private Scanner input = new Scanner(System.in);
private int counter = 1;

public static void main(String... args)
{
new Main().start();
}

public void run()
{
while(true)
{
int stacks = input.useDelimiter("\n").nextInt();
if(stacks == 0)
System.exit(0);

Scanner scanner = new Scanner(input.next());
int[] stack = new int[stacks];

int sum = 0;

for(int i = 0; i < stack.length; i++)
sum += stack[i] = scanner.nextInt();

int average = sum/stacks;

int result = 0;
for(int i = 0; i < stack.length; i++)
if(stack[i] > average)
result += stack[i] - average;

System.out.printf("Set #%d%nThe minimum number of moves is %d.%n%n",counter++, result);


}
}

}

2. C, Peter Schnitzler

/* Problem : 591
* Author : Peter Schnitzler
* Status : Ac
* Runtime : 0.01
*/
#include <stdio.h>

int main(int argc, char** argv)
{
int b;
int outputs = 1;

scanf("%d", &b);

while (b > 0)
{
int boxes[b];

int count = 0, total = 0;

for (;count < b; count++)
{
scanf("%d", boxes + count);
total += boxes[count];
}

int avra = total / b;

int moves = 0;

for (count = 0; count < b; count++)
{
if (boxes[count] > avra)
{
moves += boxes[count] - avra;
}
}

printf("Set #%d\n", outputs);
printf("The minimum number of moves is %d.\n\n", moves);
outputs++;
scanf("%d", &b);
}



return 0;
}

3. C, Tobias Fuchs

/* Accepted */

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define MAX_SETS 100
/* should be 100 * 50 + 100 = 5100, tough any amount of spaces is possible */
#define MAX_SET_INPUT_LENGTH 5100

/* k bricks in slot i: slot_config[i] = k with 1 <= k <= 100, 0 <= i < 50 */
int slot_config[50];

unsigned int sum_bricks()
{
unsigned int i, sum;
sum = 0;
for(i=0; i<50 && slot_config[i] != -1; i++) sum += slot_config[i];
return sum;
}
unsigned int sum_deviations(unsigned int num_stacks)
{
unsigned int i, sum, moves;
unsigned int default_height = sum_bricks() / num_stacks;
sum = 0;
for(i=0; i<50 && slot_config[i] != -1; i++) {
moves = abs(slot_config[i]-default_height);
sum += moves;
}
return sum;
}

int main(int argc, char * const argv[])
{
unsigned int num_stacks, num_moves, exit, move_count, move_index;
int bytes_read, nbytes, slot_index;
int moves[MAX_SETS]; /* Assuming 100 sets max */
char * token;
char * slot_config_string = (char *)malloc(nbytes+1);
exit = 0;

/* Assuming set configuration to be max. MAX_SET_INPUT_LENGTH wide */
nbytes = MAX_SET_INPUT_LENGTH;
move_index = 0;

while(!exit) {
nbytes = MAX_SET_INPUT_LENGTH;
moves[move_index] = -1;
bytes_read = getline(&slot_config_string, &nbytes, stdin);
num_stacks = atoi(slot_config_string);
if(bytes_read > 0 && num_stacks == 0) {
exit = 1;
} else {

bytes_read = getline(&slot_config_string, &nbytes, stdin);

token = strtok(slot_config_string, " ");
slot_index = 0;
slot_config[slot_index] = atoi(token);
while(token != NULL ) {
token = strtok(NULL, " ");
if(token != NULL && strcmp(token, " ") != -1) {
slot_index++;
slot_config[slot_index] = atoi(token);
/* Set next to undefined */
slot_config[slot_index+1] = -1;
}
}

num_moves = sum_deviations(num_stacks) / 2;
moves[move_index] = num_moves;
move_index++;
}
}

for(move_count = 0; move_count < MAX_SETS && moves[move_count] != -1; move_count++) {
printf("Set #%d\n", move_count+1);
printf("The minimum number of moves is %d.\n", moves[move_count]);
printf("\n");
}

return 0;
}