Luo Gu p1031

First average operator can then calculate a gap between each stack and the mean, the value of these gaps there is another array, from small to large traverse the array, if there is added to the next element put its value 0, then add a number of times. This is equivalent to each of these accounts note a heap next to a heap inside, so only the way to the right array forward, regardless of a heap greater than the average of how to go about distribution, I do not know this idea What ideas count, may be reduced governance thinking, worth learning

#include<stdio.h>

int main(void){
    int n;
    scanf("%d", &n);
    int heap[n];
    int give[n];
    int sum=0, avg;
    for(int i=0; i<n; i++)
        give[i] = 0;
    for(int i=0; i<n; i++){
        scanf("%d", &heap[i]);
        sum += heap[i];
    }
    avg = sum/n;
    for(int i=0; i<n; i++){
        give[i] = heap[i] - avg;
    }
    int steps=0;
    for(int i=0; i<n-1; i++){
        if(give[i] != 0){
            give[i+1] += give[i];
            steps++;
        }
    }
    printf("%d", steps);
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/ssNiper/p/11125285.html