Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 19420 | Accepted: 7838 |
Description
Input
The total number of bricks will be divisible by the number of stacks. Thus, it is always possible to rearrange the bricks such that all stacks have the same height.
The input is terminated by a set starting with n = 0. This set should not be processed.
Output
Output a blank line after each set.
Sample Input
6 5 2 4 1 7 5 0
Sample Output
Set #1The minimum number of moves is 5.
简单贪心问题
#include<stdio.h> #include<string.h> #include<ctype.h> #include<float.h> #include<math.h> #include<stdlib.h> #include<time.h> #include<iostream> #include<algorithm> #include<set> #include<string> #include<map> #include<vector> #include<numeric> #include<bitset> #include<queue> #include<stack> #define M(i,n,m) for(int i=n;i<m;i++) #define N(j,n,m) for(int j=n;j<m;j++) #define L(N,n) memset(N,n,sizeof(N)) const int MAX=1<<30; const int MIN=-MAX; using namespace std; double PI=acos(-1);///用C输出 int main() { int n; int a[1000]; int num=0; while(~scanf("%d",&n)) { if(!n) break; memset(a,-0,sizeof(a)); int sum=0; for(int i=0; i<n; i++) { scanf("%d",&a[i]); sum+=a[i]; } sum=sum/n; int s=0; for(int i=0; i<n; i++) if(a[i]>sum) s+=a[i]-sum; printf("Set #%d\n",++num); printf("The minimum number of moves is %d.\n\n",s); } return 0; }