591 - Box of Bricks

题目:591 - Box of Bricks


题目大意:看移动多少个砖块可以使每一组高度相同。


解题思路:就是找每组比平均少的都少多少,都加起来就是该移的砖块个数。或者找比平均多的,类似。注意每组数据后面还要在输出一行空白行。


#include<stdio.h>

int n;
const int N = 55;
int s[N];
int main() {

	int t = 0, i;
	while(scanf("%d", &n) && n) {
		t++;
		printf("Set #%d\n", t);
		int sum = 0;
		for( i = 0; i < n; i++) {
		
			scanf("%d", &s[i]);	
			sum += s[i];
		}
		sum /= n;
		int count = 0;
		for (i = 0; i < n; i++)
			if(s[i] < sum)
				count += sum - s[i];
		printf("The minimum number of moves is %d.\n\n", count);
	}
	return 0;
}


你可能感兴趣的:(591 - Box of Bricks)