Skip to content

Instantly share code, notes, and snippets.

@iporsut
Created August 16, 2012 10:24
Show Gist options
  • Save iporsut/3369099 to your computer and use it in GitHub Desktop.
Save iporsut/3369099 to your computer and use it in GitHub Desktop.
ZOJ 1251 : Box of Bricks
#include <stdio.h>
int stack[50];
int width, i, height, sum, total_move, count = 1;
int main() {
scanf("%d",&width);
while (width != 0) {
for (i = sum = 0; i < width; sum += stack[i++])
scanf("%d",&stack[i]);
height = sum / width;
total_move = 0;
for (i = 0; i < width; ++i) {
if (stack[i] > height)
total_move += (stack[i] - height);
}
printf("Set #%d\nThe minimum number of moves is %d.\n\n", count, total_move);
count++;
scanf("%d",&width);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment