New Year Transportation
来源:互联网 发布:萧然问政网络 编辑:程序博客网 时间:2024/06/15 18:22
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
8 41 2 1 2 1 2 1
YES
8 51 2 1 2 1 1 1
NO
Hint
In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.
In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit.
题解:此题唯一要注意的就是可以到达第一个点和最后一个点<span style="font-family:SimSun;background-color: rgb(255, 255, 255);">#include<cstdio>#include<cstring>int main(){int n,t;int a[30010];while(scanf("%d%d",&n,&t)!=EOF){memset(a,0,sizeof(a));for(int i=1;i<n;i++)scanf("%d",&a[i]);int i;for(i=1;i<n;){if(i>=t)break;i+=a[i];} if(i==t) printf("YES\n");elseprintf("NO\n");}return 0; } </span>
- A. New Year Transportation
- New Year Transportation
- A. New Year Transportation
- New Year Transportation
- codefoceA--New Year Transportation
- 【codeforces】New Year Transportation
- New Year Transportation
- Codeforces New Year Transportation
- 500A - New Year Transportation
- 500A. New Year Transportation
- Good Bye 2014--A. New Year Transportation
- coderforce 500A. New Year Transportation
- CodeForces 500A New Year Transportation
- CF 500 A New Year Transportation
- CF - 500A New Year Transportation
- 【暴力】Codeforces-500A New Year Transportation
- codeforces500A New Year Transportation (水题 模拟)
- New Year Transportation(CoderForces A)
- Android Context完全解析,你所不知道的Context的各种细节
- JFreeChart 简单使用
- 论学习高效
- swift3.0 URLSession网络请求工具类封装(get请求,post请求)
- 在ubuntu 14.04 64bit 上搭建c/c++集成开发环境
- New Year Transportation
- mongodb导出数据,并解决乱码问题
- wish圈:wish商户平台高清视频教程全套下载【共67集】+持续更新
- 青岛网络赛部分题解
- url的三个js编码函数escape(),encodeURI(),encodeURIComponent()简介
- 解决NGUI图片拼接中间出现1像素接缝的问题
- 一阶段暂时汇总
- 第四周项目3——单链表应用(2)
- 数据结构 链表的应用——学生信息统计