1 solutions

  • 1
    @ 2024-5-27 15:20:12
    #include <iostream>
    #include <algorithm>
    
    using namespace std;
    
    const int MAXN = 1e6 + 5;
    int a[MAXN];
    int sum,n;
    
    int main(){
    	cin >> n;
    	for (int i=1;i<=n;i++)
    		cin >> a[i], sum += a[i];
    	
    	sum /= n;
    	
    	int ans = 0;
    	for (int i=1;i<=n-1;i++)
    		if (a[i]!=sum){
    			int k = sum - a[i];	//k表示还要拿到几张牌
    			a[i+1] -= k;	//a[i]需要k牌,意味着a[i+1]要拿走k张
    			ans++; 
    		}
    		
    		
    	cout << ans << endl;
    }
    
    • 1

    Information

    ID
    31
    Time
    1000ms
    Memory
    125MiB
    Difficulty
    2
    Tags
    # Submissions
    83
    Accepted
    46
    Uploaded By