过河问题
package ojtest;

import java.util.Scanner;

public class Sohu3 {
public static int getmin(int[] arr){
if(arr.length==0)
return 0;
int jump=0,cur=0,next=0;
for(int i=0;i<arr.length;i++){
if(cur<i){
jump++;
if(cur==next)
return -1;
cur=next;
}
next=Math.max(next, i+arr[i]);
}
return cur>=arr.length?jump:(next>=arr.length?jump+1:-1);
}

public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int n=input.nextInt();
int[] arr=new int[n];
for(int i=0;i<n;i++)
arr[i]=input.nextInt();
System.out.println(getmin(arr));

}

}