pages:
  • 1
farooq SAYS

please see my solution:

in the first phase , I count the average numbers(x)

and count the subtraction of smaller numbers with x.

for example: 1 2 4 5 5 7

x = 4 so (4 - 1) + (4 - 2) = 5

is not it?

M.Khooryani SAYS

yes! it is.

your wrong answer must be related to the implementation

AMiR SAYS

As M.Khooryani said, it is correct, but you should also print the answer exactly as the sample output shows. Double check that again.

farooq SAYS

thanks for guide

farooq SAYS

this is my code

```{

import java.util.Scanner;

public class Main {

public static void main(String[] args) {
    Scanner cin = new Scanner(System.in);
    int count = 1;
    while(true){
        int m = 0;
        int n = cin.nextInt();
        if(n == 0 || n < 0)
            System.exit(0);
        if(1 <= n && n <= 50){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = cin.nextInt();
                if(a[i] > 100 || a[i] < 1)
                    break;
            }
            int sum = 0;
            for (int i = 0; i < n; i++) {
                sum += a[i];
            }
            int x = sum / n;
            for(int i = 0 ; i < n ; i++){
                if(a[i] < x)
                    m += x - a[i];
            }
        }
        System.out.println("Set #" + count);
        System.out.println("The minimum number of moves is " + m);
        count++;
    }
}

} }```

I think that problem is : ```{

if(a[i] > 100 || a[i] < 1)

break;

}```

M.Khooryani SAYS

Suppose we have a list of numbers: {1, 2, 3, 4, 5, 6} the average of numbers is 3.5 but in programming languages division of two integers is an integer according to the code, "x" value equals to 3 in this case

use: float x = (float) sum / (float) n;

AMiR SAYS

M.Khooryani said:

Suppose we have a list of numbers: {1, 2, 3, 4, 5, 6} the average of numbers is 3.5 but in programming languages division of two integers is an integer according to the code, "x" value equals to 3 in this case

use: float x = (float) sum / (float) n;

In the problem statement it has been said that

The total number of bricks will be divisible by the number of stacks. Thus, it is always possible to rearrange the bricks such that all stacks have the same height.

So int will do the job.

The problem is just you have to output a . at the end. And also the statement says there should be a blank like after each case. So a \n as well.

System.out.println("The minimum number of moves is " + m + ".\n");
M.Khooryani SAYS

great! thanks AMiR

farooq SAYS

You help me so good

thank You so much...