搬動最少方塊

 avatar
user_3763047219
c_cpp
2 years ago
1.3 kB
2
Indexable
Never
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
int main()
{
	int N = -1;
	int set = 0;
	int index = 0;
	int A[1000][50] = { 0 };
	int A2[1000][50] = { 0 };
	int N2[1000] = { 0 };
	while (N != 0) {
		scanf("%d", &N);
		if (N != 0) {
			set = set + 1;
			N2[set] = N;
			for (int i = 0; i < N; i++) {
				scanf("%d", &A[set][i]);
			}
		}
	}
	for (int j = 1; j < set; j++) {
		int total = 0;
		int count = 0;
		for (int i = 0; i < N2[j]; i++) {
			total = total + A[j][i];
		}
		int mean = 0;
		mean = total / N2[j];
		for (int i = 0; i < N2[j]; i++) {
			A2[j][i] = A[j][i] - mean;
		}
		for (int i = 0; i < N2[j]; i++) {
			if (A2[j][i] > 0) {
				count = count + A2[j][i];
			}
		}
		printf("Set #%d\n", j);
		printf("The minimum number of moves is %d.\n", count);
		printf("\n");
	}
	int total = 0;
	int count = 0;
	for (int i = 0; i < N2[set]; i++) {
		total = total + A[set][i];
	}
	int mean = 0;
	mean = total / N2[set];
	for (int i = 0; i < N2[set]; i++) {
		A2[set][i] = A[set][i] - mean;
	}
	for (int i = 0; i < N2[set]; i++) {
		if (A2[set][i] > 0) {
			count = count + A2[set][i];
		}
	}
	printf("Set #%d\n", set);
	printf("The minimum number of moves is %d.\n", count);
	printf("\n");

	
}