题目
在vivo产线上,每位职工随着对手机加工流程认识的熟悉和经验的增加,日产量也会不断攀升。
假设第一天量产1台,接下来2天(即第二、三天)每天量产2件,接下来3天(即第四、五、六天)每天量产3件 ... ...
以此类推,请编程计算出第n天总共可以量产的手机数量。
代码
(。・∀・)ノ゙嗨,这就是差距!!!
public int solution (int n) {
int production = 0;
int curProduction = 1;
int curTotal = 1;
int total = 0;
for (int i = 1; i <= n; i++) {
if (total < curTotal) {
total++;
} else {
curTotal++;
total = 1;
curProduction++;
}
production += curProduction;
}
return production;
} public int solution(int n) {
int ans = 0;
for (int i = 1; n > 0; ++i) {
ans += i * Math.min(i, n);
n -= i;
}
return ans;
} 
京公网安备 11010502036488号