代码实现:
在缺失的 n 个观测数据中,有 y 个观测数据是 x+1,其余观测数据都是x
int* missingRolls(int *rolls, int rollsSize, int mean, int n, int *returnSize) { int m = rollsSize; int sum = mean * (n + m); int missingSum = sum; for (int i = 0; i < m; i++) { missingSum -= rolls[i]; } if (missingSum < n || missingSum > 6 * n) { *returnSize = 0; return NULL; } int x = missingSum / n, y = missingSum % n; int *res = (int*)malloc(sizeof(int) * n); for (int i = 0; i < n; i++) { res[i] = x + (i < y ? 1 : 0); } *returnSize = n; return res; }