牛客网真题-61-机器人跳跃问题

机器人跳跃问题

http://www.nowcoder.com/questionTerminal/7037a3d57bbd4336856b8e16a9cafd71

仔细读题目,e(k)+e(k)-H(k+1)=e(k+1)
e(k)=(ek+1)+H(k+1))/2,注意这是临界条件,要用浮点数,完了向上取整。

import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        double[] ints = new double[n];
        for(int i = 0; i < n; i++){
            ints[i] = (double) scanner.nextInt();
        }
        double e = 0;
        int index = n - 1;
        while (index >= 0) {
            e = (e + ints[index]) / 2;
            index--;
        }
        //        System.out.println(e);
        System.out.println((int) Math.ceil(e));
    }
}

全部评论

相关推荐

09-17 10:53
四川大学 C++
牛客91242815...:会写标书没有任何卵用,鉴定为横向垃圾导师的受害者
点赞 评论 收藏
分享
评论
3
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务