返回题库

匿名计算平均工资

Quant Salary

专题
Brainteaser / 脑筋急转弯
难度
L2

题目详情

8 个量化从业者想计算行业平均工资,但没人愿意向他人透露自己的工资。如何在不暴露任何个人工资的情况下,集体计算平均工资?

Eight quants each want to know the average salary in their industry, but no one wants to reveal their own salary to the others. How can they collectively compute the average without exposing any individual’s salary?

解析

使用“随机掩码 + 逐步累加”方法:

  1. 第 1 人选一个大随机数 RR,把 S1+RS_1+R 传给第 2 人。
  2. 第 2 人加上自己的工资 S2S_2,传给第 3 人……依次类推。
  3. 最后一个人得到 i=18Si+R\sum_{i=1}^8 S_i + R,传回第 1 人。
  4. 第 1 人减去 RR 得到总和 Si\sum S_i,再除以 8 得平均数。

他人只看到“部分和”,看不到任何单个人的工资。


Original Explanation

They can use a secure “random offset” method. For example:

  1. The first person picks a random large number RR and adds it to their salary S1S_1, writing down S1+RS_1 + R (hidden from others except passing along a sum).
  2. They pass this partial sum to the second person, who adds S2S_2, etc.
  3. Finally, the sum i=18Si+R\sum_{i=1}^8 S_i + R is returned to the first person, who subtracts RR, leaving i=18Si\sum_{i=1}^8 S_i.
  4. Divide by 8 for the average.

No one sees each other’s salaries, only partial sums.