http://codevs.cn/problem/1098/
Q:n stacks of cards, each stack of cards randomly, each pile of cards can only move to the adjacent card stack, the minimum number of moves, so that the number of cards per stack consistent.
A: Sweep from beginning to end, as long as the current stack of cards is not the average number of cards per stack, it will be more or less of the cards moved or taken from the next pile of cards, while the number of moves plus 1
#include <bits/stdc++.h>using namespacestd;intp[ the];intN;intsum, avg;intans;intMain () { while(~SCANF ("%d", &N)) {Sum=0; Ans=0; for(inti =0; I < n; i++) {scanf ("%d", &P[i]); Sum+=P[i]; } avg= SUM/N; for(inti =0; I < n; i++){ if(P[i] <avg) {P[i+1]-= avg-P[i]; P[i]=avg; Ans++; } Else if(P[i] >avg) {P[i+1] + = p[i]-avg; P[i]=avg; Ans++; }} printf ("%d\n", ans); } return 0;}
"Greedy" "Codevs" 1098 split Solitaire