*[topcoder]JumpFurther
生活随笔
收集整理的這篇文章主要介紹了
*[topcoder]JumpFurther
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
http://community.topcoder.com/stat?c=problem_statement&pm=12300&rd=15699
題意:有一個(gè)無限長的階梯,i從1到N,每次跳i步或不跳;有一個(gè)階梯是壞的,不能跳,問最多跳多遠(yuǎn)。
分析:貪心的跳,當(dāng)跳到壞階梯時(shí),就躲開,怎么躲,就是第一步不跳。那么此時(shí)和壞臺(tái)階差一步,只有i為0時(shí)下一步才為1,但i從0開始,所以不會(huì)發(fā)生。
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;} }
轉(zhuǎn)載于:https://www.cnblogs.com/lautsie/p/3490379.html
總結(jié)
以上是生活随笔為你收集整理的*[topcoder]JumpFurther的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 转 安装php时报gd相关的错误(gd_
- 下一篇: 创建 gif