AcWing 730. 机器人跳跃问题——Java代码版
原题链接
中等
作者:
三玖天下第一
,
2021-04-04 15:21:36
,
所有人可见
,
阅读 354
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(reader.readLine().trim());
String[] temp = reader.readLine().split(" ");
int[] h = new int[n];
for (int i = 0; i < n; i++) {
h[i] = Integer.parseInt(temp[i]);
}
int l = 0, r = 100000;
while(l < r){
int mid = (l + r) >> 1;
int e = mid;
for (int i = 0; i < n && e >= 0 && e <= 100000; i++) {
e = 2*e - h[i];
}
if (e < 0) l = mid + 1;
else r = mid;
}
System.out.println(l);
}
}