-4

这是 Zyflair 的topcoder SRM 569 DIV 2 问题 250的解决方案

我无法理解代码或它是如何工作的,有人可以解释或简化它。

public int countSupervisors(int[] students, int Y, int J){
  for(int i = 0,Y2 = Y + (Y = 0),J2=J+(J=0) ;i<students.length; i++,Y +=students [i -1 ] ){
   J =Math.max(J,-(Math.max(0, students[i]-Y2)+J2-1)/J2+(students[i] = (students[i]+J2-1)/J2));
        }
  return Y-J;
}
4

1 回答 1

1

我现在真的没有时间研究这个问题,但这里有一点简化:

// Y2 = Y + (Y = 0)
int Y2 = Y;
Y = 0;

// J2 = J + (J = 0)
int J2 = J;
J = 0;

// Note that, since we've just set Y and J to 0,
//   we may as well have used different variables

for (int i = 0; i < students.length; i++)
{
   int temp = (students[i] + J2 - 1) / J2;
   J = Math.max(J, -(Math.max(0, students[i] - Y2) + J2 - 1) / J2 + temp);
   Y += temp;
}
return Y-J;
于 2013-07-03T22:39:34.080 回答