Q591:Box of Bricks
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=7&problem=532&mosmsg=Submission+received+with+ID+17576677
import java.util.*;
public class test {
public static void main(String[] args) {
Scanner scn =new Scanner (System.in);
int n,count=0;
while((n=scn.nextInt())!=0){
int arr[]=new int [50],tot=0,max=0;
for(int i=0;i<n;i++){
arr[i]=scn.nextInt();
tot+=arr[i];
}
tot/=n;
for(int i=0;i<n;i++){
if(tot<arr[i])max+=arr[i]-tot;
}
System.out.printf("Set #%d\n",++count);
System.out.printf("The minimum number of moves is %d.\n",max);
}
}
}
/*
題目:Q591:Box of Bricks
作者:1010
時間:西元 2016 年 6 月 */
Sample Iutput
6
5 2 4 1 7 5
3
1 1 1
0
5 2 4 1 7 5
3
1 1 1
0
Sample Output
Set #1 The minimum number of moves is 5. Set #2 The minimum number of moves is 0.
困難度 ★
*注意每筆後面要多加一行換行以免測資過不了
計算平均大於的相減
沒有留言:
張貼留言