码迷,mamicode.com
首页 > Web开发 > 详细

JSK 18: 跳跃游戏

时间:2018-07-19 17:31:38      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:img   cst   style   ++   color   tom   std   否则   als   

技术分享图片
#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

 

JSK 18: 跳跃游戏

标签:img   cst   style   ++   color   tom   std   否则   als   

原文地址:https://www.cnblogs.com/Rhythm-/p/9336648.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!