Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1326
Main topic:
To the n wall, each wall of different heights, the minimum number of moving block to make the wall of the same height.
Problem Solving Ideas:
Find the average wall height (that is, the height of the last wall), traverse all the walls, if less than the average wall, then the average wall minus the height is the height to move, statistics all the need to "fill" the height. Note the output.
AC Code:
1#include <bits/stdc++.h>2 using namespacestd;3 intMain ()4 {5 intn,k=1;6 while(SCANF ("%d", &n)!=eof&&N)7 {8 intna[n+1],cut=0;9 for(intI=0; i<n; i++)Tenscanf"%d", &na[i]), cut+=Na[i]; One intavg=cut/N; Acut=0; - for(intI=0; i<n; i++) - if(na[i]<avg) thecut+= (avg-na[i]); -printf"Set #%d\n", k++); -printf"The minimum number of moves is%d.\n\n", cut); - } + return 0; -}
HDU 1326 Box of bricks (water ~ average height for minimum moving bricks)