直接上题目:
圆桌旁坐着n个人,每个人有一定数量的金币,金币数量能被n整除。每个人可以给他左右相邻的人分一些金币,最终使得金币数量相等。
4
1 2 5 4
4
根据解析可得:先根据获得的金币,减掉“M”,根据得到的结果中位数与其他的相减得到的绝对值相加。
C[i] = c[i-1]+A[i]-M ans += abs(x1-C[i])
本文采用的方法:
C[i] = A[i]-M ans += abs(x1-C[i])
/*
分金币:
圆桌旁坐着n个人,每个人有一定数量的金币,金币数量能被n整除。每个人可以给他左右相邻的人分一些金币,最终使得金币数量相等。
4
1 2 5 4
4
*/
#include <iostream>
using namespace std;
const int Max = 10000;
int main(void)
{
int N = 0, iAvg = 0;
int A[Max];
int B[Max];
cin >> N;
for(int i = 0; i < N