日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

CodeForces - 500A-New Year Transportation(模拟)

發布時間:2023/12/2 编程问答 47 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CodeForces - 500A-New Year Transportation(模拟) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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?-?1?positive 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?-?1?portals, 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?tby 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".

Examples

Input

8 4 1 2 1 2 1 2 1

Output

YES

Input

8 5 1 2 1 2 1 1 1

Output

NO

Note

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.

題解:模擬更新可以到達的位置,然后加上該位置下標的值

代碼:

#include<cstdio> #include<cstring> #include<algorithm> #include<iostream>using namespace std;int main() {int n,m;cin>>n>>m;int a[30005];for(int t=1; t<=n-1; t++) {scanf("%d",&a[t]);}int flag=0;for(int t=1; t<n;) {t=t+a[t];//cout<<t<<endl;if(t==m) {flag=1;}}if(flag==1) {cout<<"YES"<<endl;} else {cout<<"NO"<<endl;}return 0; }

?

轉載于:https://www.cnblogs.com/Staceyacm/p/10781884.html

總結

以上是生活随笔為你收集整理的CodeForces - 500A-New Year Transportation(模拟)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。