*[topcoder]JumpFurther
http://community.topcoder.com/stat?c=problem_statement&pm=12300&rd=15699
题意:有一个无限长的阶梯,i从1到N,每次跳i步或不跳;有一个阶梯是坏的,不能跳,问最多跳多远。
分析:贪心的跳,当跳到坏阶梯时,就躲开,怎么躲,就是第一步不跳。那么此时和坏台阶差一步,只有i为0时下一步才为1,但i从0开始,所以不会发生。
public class JumpFurther { public int furthest(int N, int badStep) { int step = 0; for (int i = 1; i <= N; i++) { step += i; if (step == badStep) { step--; } } return step; } }