*[topcoder]JumpFurther
生活随笔
收集整理的這篇文章主要介紹了
*[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;} }
轉載于:https://www.cnblogs.com/lautsie/p/3490379.html
總結
以上是生活随笔為你收集整理的*[topcoder]JumpFurther的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 转 安装php时报gd相关的错误(gd_
- 下一篇: 创建 gif