(UVA)591-堆積木


#include<stdio.h>
int main(){
int num_stack;
int set = 1;
while (scanf("%d", &num_stack) != EOF){ 

  if (num_stack == 0) break;

  int i, temp, box[100] = { 0 };

  for (i = 0; i < num_stack; i++)  scanf("%d", &box[i]);

  temp = i;
  int sum = 0;
 
 for (i = 0; i<num_stack; i++) /*全部相加*/
 sum += box[i];

 int average;
 average = sum / i; /*算平均值*/

 int count = 0;
 for (i = 0; i<num_stack; i++) /*只需補齊不足的*/
 { if (box[i]<average)

    count += average - box[i]; /*總移動數*/
}

  printf("Set #%d\n", set);

  printf("The minimum number of moves is %d.\n\n", count); /*記得換行兩次*/

  set++;

 }
 return 0;
}

留言

這個網誌中的熱門文章

Bundle Adjustment 光束平差法

Structure From Motion