P1031 均分纸牌

https://www.luogu.com.cn/problem/P1031

#include <bits/stdc++.h>
#define int long long
using namespace std;

int n,s;
int a[105];

signed main() {
    //freopen("in","r",stdin);
    ios::sync_with_stdio(0);
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i],s+=a[i];
    s /= n;
    int cnt = 0;
    for(int i = 0; i < n; i++){
        if(a[i] - s){
            a[i + 1] += a[i] - s;
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}
View Code

原文地址:https://www.cnblogs.com/xcfxcf/p/12367894.html