【HDOJ】1326 Box of Bricks
大水题一道,千万别理解复杂。
#include <stdio.h> #define MAXNUM 50 int main() { int heights[MAXNUM], n; int i, j, tmp, avg; j = 0; while (1) { scanf("%d", &n); if (n == 0) break; tmp = 0; for (i=0; i<n; ++i) { scanf("%d", &heights[i]); tmp += heights[i]; } avg = tmp / n; tmp = 0; for (i=0; i<n; ++i) { if (heights[i] > avg) { tmp += (heights[i]-avg); } } printf("Set #%d\n", ++j); printf("The minimum number of moves is %d.\n\n", tmp); } return 0; }