Description

New Year is coming in Line World! In this world, there are n cells numbered by integers from 1 to n, as a 1 × n board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.

So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of n - 1positive integers a1, a2, ..., an - 1. For every integer i where 1 ≤ i ≤ n - 1 the condition 1 ≤ ai ≤ n - i holds. Next, he made n - 1portals, numbered by integers from 1 to n - 1. The i-th (1 ≤ i ≤ n - 1) portal connects cell i and cell (i + ai), and one can travel from cell i to cell (i + ai) using the i-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell(i + ai) to cell i using the i-th portal. It is easy to see that because of condition 1 ≤ ai ≤ n - i one can't leave the Line World using portals.

Currently, I am standing at cell 1, and I want to go to cell t. However, I don't know whether it is possible to go there. Please determine whether I can go to cell t by only using the construted transportation system.

Input

The first line contains two space-separated integers n (3 ≤ n ≤ 3 × 104) and t (2 ≤ t ≤ n) — the number of cells, and the index of the cell which I want to go to.

The second line contains n - 1 space-separated integers a1, a2, ..., an - 1 (1 ≤ ai ≤ n - i). It is guaranteed, that using the given transportation system, one cannot leave the Line World.

Output

If I can go to cell t using the transportation system, print "YES". Otherwise, print "NO".

Sample Input
Input Output
YES
Input Output
NO
Hint
In the first sample, the visited cells are: , , ; so we can successfully visit the cell . In the second sample, the possible cells to visit are: , , , , , ; so we can't visit the cell 5, which we want to visit.

题目链接:http://codeforces.com/problemset/problem/500/A

************************************************

题意:给你n个数下标为1~n,每个位置给的a[n]就是站在这个位置接着可以走的步数,要求你判断是否可以访问到下标为t的位置。

分析:直接模拟,然后进行判断就好。

AC代码:

 #include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<queue>
#include<algorithm>
#include<cmath>
#include<iostream> using namespace std;
typedef long long LL; #define INF 0x3f3f3f3f
#define N 41000
#define MAXN 100000000
#define mod 1000000007 int a[N]; int main()
{
int n,t,i; while(scanf("%d%d", &n,&t) != EOF)
{
for(i=; i<n; i++)
scanf("%d", &a[i]); i=;
while()
{
i=i+a[i];
if(i==t)
{
printf("YES\n");
break;
}
if(i>t)
{
printf("NO\n");
break;
}
} }
return ;
}

CodeForces 500 A. New Year Transportation的更多相关文章

  1. Codeforces 500 E. New Year Domino

    \(>Codeforces \space 500 E. New Year Domino<\) 题目大意 : 数轴上有序排列着 \(n\) 块多米诺骨牌, 第 \(i\) 块骨牌坐标为 \( ...

  2. 洛谷 P5089: CodeForces #500 (Div. 1) B / 1012B : Chemical table

    题目传送门:洛谷P5089. 题意简述: 一张 \(n \times m\) 的表格,有一些格子有标记,另外一些格子没有标记. 如果 \((r_1,c_1),(r_1,c_2),(r_2,c_1)\) ...

  3. LibreOJ 题解汇总

    目录 #1. A + B Problem #2. Hello, World! #3. Copycat #4. Quine #7. Input Test #100. 矩阵乘法 #101. 最大流 #10 ...

  4. codeforces 500A. New Year Transportation

    题目链接:http://codeforces.com/problemset/problem/500/A 题目意思:给出 n-1 个 cell,每个 cell 有一个值 ai,表示在这个编号为 i 的 ...

  5. Codeforces Round #500 (Div. 2) [based on EJOI]

    Codeforces Round #500 (Div. 2) [based on EJOI] https://codeforces.com/contest/1013 A #include<bit ...

  6. 【最大流】ECNA 2015 F Transportation Delegation (Codeforces GYM 100825)

    题目链接: http://codeforces.com/gym/100825 题目大意: N(N<=600)个点,每个点有个名字Si,R(R<=200)个生产商在R个点上,F(F<= ...

  7. Codeforces Round 500 (Div 2) Solution

    从这里开始 题目地址 瞎扯 Problem A Piles With Stones Problem B And Problem C Photo of The Sky Problem D Chemica ...

  8. Codeforces 724E Goods transportation(最小割转DP)

    [题目链接] http://codeforces.com/problemset/problem/724/E [题目大意] 每个城市有pi的物品可以运出去卖,si个物品可以买, 编号小的城市可以往编号大 ...

  9. Codeforces Round #500 (Div. 2) BC

    CodeForces 1013B And CodeForces 1013C  Photo of The Sky B 可以发现只有一次与操作是有意义的,所以答案只有-1,0,1,2四种情况 #inclu ...

随机推荐

  1. lucene索引的创建与搜索

    package com.cs.multi; import java.io.File;import java.io.IOException; import org.apache.lucene.analy ...

  2. Unity3D 回合制 网上源码 目前还在研究构思

    我们已将回合制的战斗模式讲解得很清楚了.那么,如果在Unity3D游戏中实现一个回合制游戏呢?我们从最简单的一对一模式来设计回合制游戏的原型.我们可以游戏的状态划分为下面三种状态:        1. ...

  3. ural 1146. Maximum Sum(动态规划)

    1146. Maximum Sum Time limit: 1.0 second Memory limit: 64 MB Given a 2-dimensional array of positive ...

  4. JSONModel解析数据成Model

    转自:http://blog.csdn.net/smking/article/details/40432287 JSONModel, Mantle 这两个开源库都是用来进行封装JSON->Mod ...

  5. php精度计算问题

    如果用php的+-*/计算浮点数的时候,可能会遇到一些计算结果错误的问题,比如echo intval( 0.58*100 );会打印57,而不是58,这个其实是计算机底层二进制无法精确表示浮点数的一个 ...

  6. 小飞淙在博客上的第一天——NOIP201505转圈游戏

    原本我是在word文档上写这种东西的,在杨老师的“强迫”下,我开始写了博客. 这是我在博客上的第一天,就先来个简单的,下面请看题: 试题描述  有n个小伙伴(编号从0到n-1)围坐一圈玩游戏.按照顺时 ...

  7. 算法入门(C++)

    iostream,这个头文件里有很多常用的函数,比如swap交换两个变量的值,max求两个值的最大值等. cstdio头文件,这个头文件里包含C风格的输入输出.如果你之前学习过C++语言应该知道cin ...

  8. centos7.2自带的php5.4升级为5.6

    参考:http://jingyan.baidu.com/article/380abd0a1f176c1d91192c4b.html 今天在新购的阿里云上部署个phpmyadmin,结果显示了个如下信息 ...

  9. ASP.NET MVC 使用带有短横线的html Attributes

    我们常常需要一个文本框来输入用户名,在asp.net mvc 中可以使用 TextBoxFor.有时候我们想为这个文本框添加一些特性,比如 html5 的data-,如果直接写data-是会提示错误的 ...

  10. 手把手教你ranorex_android自动化测试第一个示例

    要说android的自动化,那真是折腾死我了,从早期的monkeyrunner,到后来的robotium,再到最新的uiautomator,各有各的问题,总之性价比都不够高,不太适合我的使用场景.于是 ...