UVA – 591 – Box of Bricks

  • ID : UVA – 591 – Box of Bricks
  • Submissions : Java – Accepted
  • Difficulty : Easy.
  • Type : Simple Math.
  • Time for Submission :30 minutes
  • Solution Description :
    • calculate the average and trim all walls above the average and add the trimmed part to the counter.
  • Problems :
    • No problems, it went smoothly.
  • Code :

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int T;
		int Kase =1;
		while ((T = in.nextInt()) != 0) {
			int[] w = new int[T];
			int avg = 0;
			while (T-- != 0) {
				w[T] = in.nextInt();
				avg += w[T];
			}
			avg /= w.length;
			int carried = 0;
			for (int n : w) {
				if (n > avg)
					carried += n - avg;
			}
			System.out.println("Set #"+ Kase++);
			System.out.println("The minimum number of moves is "+carried+".");
			System.out.println("");
		}
	}
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: