POJ 1477
1 #include <iostream> 2 #define MAXN 100 3 using namespace std; 4 5 int _[MAXN]; 6 7 int main() 8 { 9 //freopen("acm.acm","r",stdin); 10 int n; 11 int i; 12 int ave; 13 int sum; 14 int time = 0; 15 while(cin>>n,n) 16 { 17 sum = 0; 18 for(i = 0; i < n; ++ i) 19 { 20 cin>>_[i]; 21 sum += _[i]; 22 } 23 ave = sum/n; 24 sum = 0; 25 for(i = 0; i < n; ++ i) 26 { 27 sum += abs(_[i]-ave); 28 } 29 cout<<"Set #"<<++ time<<endl; 30 cout<<"The minimum number of moves is "; 31 cout<<sum/2<<"."<<endl; 32 cout<<endl; 33 } 34 }
关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。
技术网站地址: vmfor.com