Garlic Guest Jumping Game

Source: Internet
Author: User

Jumping game

Given a non-negative integer array, assume that your initial position is the first subscript of the array.

Each element in the array represents the maximum length that you can jump in that position.

Make sure you are able to jump to the last subscript of the array.

For example:

A = [2,3,1,1,4],

return true.

A = [3,2,1,0,4],

return FALSE.

Format:

The first line enters a positive integer n, the next line, and the input array a[n]. If you can skip to the last subscript, output "true", otherwise output "false"

Sample input
52 0 2) 0 1
Sample output
True

1#include"iostream"2 #defineMAX 100003 using namespacestd;4 5 intJumpintNint*a,intp)6 {7     if(P >=N)8         return 1;9      for(inti = a[p]; I>0; i--)Ten     { One         if(Jump (n, a, p + i) = =1) A             return 1; -         Else -A[p + i] =-1;//p+1 position is not the last . the     } -     return 0; - } -  + intMain () - { +     intA[max]; A     intN,tag; atTag =0; -CIN >>N; -      for(inti =0; i<n; i++) -     { -CIN >>A[i]; -     } in  -     if(Jump (N,a,0)) tocout <<"true"; +     Else -cout <<"false"; the  *}

Garlic Guest Jumping Game

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.