JSK 18: 跳跃游戏
题目描述
输入
输出
样例输入
5
2 0 2 0 1
样例输出
true
#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[],dp[];
void init() {
cin>>n;
range(i,,n-)cin>>num[i];
}
void solve(){
bool ans=false;
if(n==)ans=true;
int pos=;
while(pos<n-){
pos+=num[pos];
if(!num[pos]&&pos!=n-)break;
if(pos==n-){ans=true;break;}
}
cout<<(ans?"true":"false")<<endl;
}
int main() {
init();
solve();
return ;
}
JSK 18: 跳跃游戏的更多相关文章
- lintcode: 跳跃游戏 II
跳跃游戏 II 给出一个非负整数数组,你最初定位在数组的第一个位置. 数组中的每个元素代表你在那个位置可以跳跃的最大长度. 你的目标是使用最少的跳跃次数到达数组的最后一个位置. 样例 给出数组A = ...
- lintcode : 跳跃游戏
跳跃游戏 给出一个非负整数数组,你最初定位在数组的第一个位置. 数组中的每个元素代表你在那个位置可以跳跃的最大长度. 判断你是否能到达数组的最后一个位置. 样例 A = [2,3,1,1,4],返回 ...
- 【LeetCode每天一题】Jump Game II(跳跃游戏II)
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- LeetCode(45): 跳跃游戏 II
Hard! 题目描述: 给定一个非负整数数组,你最初位于数组的第一个位置. 数组中的每个元素代表你在该位置可以跳跃的最大长度. 你的目标是使用最少的跳跃次数到达数组的最后一个位置. 示例: 输入: [ ...
- 计蒜客-跳跃游戏二 (简单dp)
题目链接:https://nanti.jisuanke.com/t/20 跳跃游戏二 给定一个非负整数数组,假定你的初始 ...
- [Leetcode]44.跳跃游戏Ⅰ&&45.跳跃游戏Ⅱ
跳跃游戏链接 给定一个非负整数数组,你最初位于数组的第一个位置. 数组中的每个元素代表你在该位置可以跳跃的最大长度. 判断你是否能够到达最后一个位置. 示例 1: 输入: [2,3,1,1,4] 输出 ...
- 跳跃游戏 12 · Jump Game 12
跳跃游戏 1 [抄题]: [思维问题]: [一句话思路]: [输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入): [画图]: [一刷]: 由于要用itera ...
- [luogu4255]公主の#18文明游戏
[luogu4255]公主の#18文明游戏 luogu 发现没有连边,只有删边? 考虑倒着做 开map记M[i][j]表示编号为i的并查集,信仰j的人数 s[i]表示编号为i的并查集的总人数 首先询问 ...
- LeetCode:跳跃游戏【55】
LeetCode:跳跃游戏[55] 题目描述 给定一个非负整数数组,你最初位于数组的第一个位置.数组中的每个元素代表你在该位置可以跳跃的最大长度.判断你是否能够到达最后一个位置. 示例 1: 输入: ...
随机推荐
- ptmalloc,tcmalloc和jemalloc内存分配策略研究 ? I'm OWen..
转摘于http://www.360doc.com/content/13/0915/09/8363527_314549949.shtml 最近看了glibc的ptmaoolc,Goolge的tcmall ...
- Jmeter mysql性能测试
一:首先建立jdbc connection configuration,设置参数如图 1.variable name 参数名称,与后面的sample中设置的variable name一致.含义为:通过 ...
- 不吹不擂,你想要的Python面试都在这里了【315+道题】+精心整理的解答
Part01-Py基础篇(80) Part02-网络编程和并发(34) Part03-数据库和缓存(46) Part04-前端框架和其他(155) Part01-Py基础篇(80) 1.为什么学习Py ...
- Linux认知之旅【02 装个软件玩玩】!
〇.命令行终端熟悉了吗? 1.没有仔细研究上一篇文章? 拿上看看这几个命令:ls.cd.cp.mv.rm.mkdir.touch.cat.less.恩,暂时这些够用了! 什么?你连虚拟机也没装! 感谢 ...
- C++树的建立和遍历
#include<iostream.h> typedef char TElemtype; typedef struct Btree { TElemtype data; struct Btr ...
- Android记事本10
昨天: 从Activity中返回数据. 请求码和结果码的作用. 今天: Activity的启动模式. 遇到的问题: 无.
- java作业 2017.10.14
课后作业一 1.设计思想: (1)通过组合数公式计算:分别输入中的n和k的值.定义一个计算n!的方法,然后调用方法分别计算出n!,k!,(n-k)!,然后通过公式=n!/(k!*(n-k)!)算出的值 ...
- Custom LDAP Monitor Does Not Work
Custom LDAP Monitor Does Not Work https://www.poppelgaard.com/netscaler-case-study-custom-ldap-monit ...
- yii2.0查询慢的原因
最近使用Yii2.0来搭建项目,测试的时候发现无论是请求列表数据还是发布数据,都很慢,然后我一步一步打印时间来查看哪里的问题,始终找不到原因,最后在网上看到这篇: 'db' => [ 'clas ...
- php的post
代码的顺序不能乱,否则会提交错误 $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HE ...