ZOJ4118 Stones in the Bucket
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                ZOJ4118 Stones in the Bucket
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.                        
                                水題 給出n個數(shù) 只能讓某個數(shù)-1 或者 讓某個數(shù)-1另一個數(shù)+1 使最后n個數(shù)都相等 問最少的操作數(shù)
AC代碼:
1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 typedef unsigned long long ull; 5 6 ll a[100005]; 7 8 int main(){ 9 ll t, n, k; 10 ll ans, sum; 11 cin>>t; 12 while (t--){ 13 memset(a, 0, sizeof(a)); 14 cin>>n; 15 ans = 0, sum = 0; 16 for (int i = 0; i < n; i++){ 17 cin>>a[i]; 18 sum += a[i]; 19 } 20 sum /= n; 21 for (int i = 0; i < n; i++) 22 if (a[i] > sum) 23 ans += a[i] - sum; 24 cout<<ans<<endl; 25 } 26 return 0; 27 }轉(zhuǎn)載于:https://www.cnblogs.com/Misuchii/p/10896902.html
總結(jié)
以上是生活随笔為你收集整理的ZOJ4118 Stones in the Bucket的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: icon组件
- 下一篇: 在执行方法和Web资源中获取传递过来参数
