"Greedy" Sharing solitaire time limit: 1 Sec memory limit: up to MB Title Description
There were N piles of cards, numbered 1,2,...,n. There are several sheets on each heap, but the total number of cards must be multiples of n. You can take a number of cards on either heap and move them. The rules for the move are: the cards on the numbered 1 heap can only be moved to the heap numbered 2, and the cards taken on the heap numbered n can only be moved to the heap numbered N-1, and the cards on the other heap may be moved to the adjacent left or right heap. now it's time to find a way to move, with the fewest number of moves to make as many cards as you can on each heap. For example, n=4,4 heap card number is: ①9②8③17④6 Move 3 times can achieve the purpose: from ③ take 4 cards put to ④ (9 8), from ③ take 3 cards put to ② (9), from ② take 1 cards and put them in ① (10 10 10 10).
Input
The input file includes two rows of data. The first action N heap of Cards (1<=n<=100). the second behavior N heap solitaire in each pile of solitaire initial number A1,a2,...,an (l<=ai<=10000).
Output
The only line in the output file, which is the minimum number of moves when all the heaps are equal.
Sample input
49 8 17 6
Sample output
3
1#include <iostream>2 3 using namespacestd;4 intN;5 inta[111];6 intsum,t;7 intavg;8 intMain ()9 {Ten One while(cin>>N) A { -sum=0; t=0; - for(intI=0; i<n;i++) the { -Cin>>A[i]; -sum+=A[i]; - } +avg=sum/N; - for(intI=0; i<n;i++) + { A if(a[i]!=avg) at { -a[i+1]-=avg-A[i]; -t++; - } - } -cout<<t<<Endl; in } - return 0; to}
"Greedy" evenly split the card