HDU 2088 Box of Bricks
这题仔细想以下就知道其实最少的次数就是所有高于平均高度的墙都要移动一次就行了,只是需要注意输出格式,汗,PE了三次,最后求助大牛才解决
#include<stdio.h> int main( ) { int num[1000],min,n,ave,r = 0; while( scanf( "%d",&n ),n ) { ave = min = 0; for( int i = 0; i < n; ++i ) scanf( "%d",&num[i] ),ave += num[i]; ave /= n; for( int i = 0; i < n; ++i ) if( num[i] > ave ) min += (num[i] - ave ); printf( "Set #%d\n",++r ); printf( "The minimum number of moves is %d.\n",min ); if( r != 0 ) puts( "" ); } return 0; }
本人还是新手 ,转载请注明来自Lvsi‘s home