zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    MYSQL关于数据库的操作命令
    理解js中的原型和原型链
    float引起的高度塌陷问题
    使用webpack2.0 搭建前端项目
    jquery插件开发总结
    js中的OOP编程
    关于gulp的基本使用
    关于requireJs的学习总结
    vuex的学习总结
    事件中的target与currentTarget的区别
  • 原文地址:https://www.cnblogs.com/Rhythm-/p/9336648.html
Copyright © 2011-2022 走看看