JSK 18: 跳跃游戏

#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#define range(i,a,b) for(int i=a;i<=b;++i)
#define LL long long
#define rerange(i,a,b) for(int i=a;i>=b;--i)
#define fill(arr,tmp) memset(arr,tmp,sizeof(arr))
using namespace std;
int n,num[505],dp[505];
void init() {
    cin>>n;
    range(i,0,n-1)cin>>num[i];
}
void solve(){
    bool ans=false;
    if(n==1)ans=true;
    int pos=0;
    while(pos<n-1){
        pos+=num[pos];
        if(!num[pos]&&pos!=n-1)break;
        if(pos==n-1){ans=true;break;}
    }
    cout<<(ans?"true":"false")<<endl;
}
int main() {
    init();
    solve();
    return 0;
}
View Code

 

posted @ 2018-07-19 16:34  RhythmLian  阅读(463)  评论(0编辑  收藏  举报