CodeForces 500 A. New Year Transportation
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的更多相关文章
- Codeforces 500 E. New Year Domino
\(>Codeforces \space 500 E. New Year Domino<\) 题目大意 : 数轴上有序排列着 \(n\) 块多米诺骨牌, 第 \(i\) 块骨牌坐标为 \( ...
- 洛谷 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)\) ...
- LibreOJ 题解汇总
目录 #1. A + B Problem #2. Hello, World! #3. Copycat #4. Quine #7. Input Test #100. 矩阵乘法 #101. 最大流 #10 ...
- codeforces 500A. New Year Transportation
题目链接:http://codeforces.com/problemset/problem/500/A 题目意思:给出 n-1 个 cell,每个 cell 有一个值 ai,表示在这个编号为 i 的 ...
- Codeforces Round #500 (Div. 2) [based on EJOI]
Codeforces Round #500 (Div. 2) [based on EJOI] https://codeforces.com/contest/1013 A #include<bit ...
- 【最大流】ECNA 2015 F Transportation Delegation (Codeforces GYM 100825)
题目链接: http://codeforces.com/gym/100825 题目大意: N(N<=600)个点,每个点有个名字Si,R(R<=200)个生产商在R个点上,F(F<= ...
- Codeforces Round 500 (Div 2) Solution
从这里开始 题目地址 瞎扯 Problem A Piles With Stones Problem B And Problem C Photo of The Sky Problem D Chemica ...
- Codeforces 724E Goods transportation(最小割转DP)
[题目链接] http://codeforces.com/problemset/problem/724/E [题目大意] 每个城市有pi的物品可以运出去卖,si个物品可以买, 编号小的城市可以往编号大 ...
- Codeforces Round #500 (Div. 2) BC
CodeForces 1013B And CodeForces 1013C Photo of The Sky B 可以发现只有一次与操作是有意义的,所以答案只有-1,0,1,2四种情况 #inclu ...
随机推荐
- Chapter 16_3 多重继承
在Lua中进行面向对象编程时有几种方法,上一小结介绍了一种使用__index元方法的做法. 下面要介绍另一种方法,可以在Lua中实现多继承. 关键一点,在于用函数作为__index元字段. 多重继承意 ...
- spring源码
今天看了看spring对于视图解析的源码,发现还不是那些思想,internalResourceView里的一个渲染方法 protected void exposeModelAsRequestAttri ...
- Ubuntu14.04下安装redis
1.首先在官网上下载redis压缩包 redis-3.2.0.tar.gz 2.解压到到当前文件夹(这里可以解压到随意位置) tar zvxf redis-3.2.0.tar.gz 3.切换到redi ...
- Python 学习笔记4
我是一个艺术家. 今天继续学习python啊.争取看到python流程控制.
- 接入支付宝出现交易订单处理失败,请稍后再试(ALI64)的错误【转】
接入第三方平台的时候,有时虽然按照文档来做,但是总是还会有各种各样的问题. 上次在接入支付宝的时候就碰到了交易订单处理失败,请稍后再试(ALI64)这样的错误,后来经过排查和总结,一般来讲这种问题都是 ...
- Ubuntu iptalbes 保存配置
ubuntu 保存防火墙命令,iptables方式:1.iptables 配置好策略2.iptables-save > /etc/network/iptables.up.rules ,配置的策 ...
- 711B - Chris and Magic Square 模拟
题目大意:在num[i][j]==0处填一个数使每行,每列,对角线的和相同,若果有多种答案输出一种. 题目思路:模拟 #include<iostream> #include<algo ...
- C++ 空类默认产生的类成员函数
C++的空类有哪些成员函数:. 缺省构造函数.. 缺省拷贝构造函数.. 缺省析构函数.. 缺省赋值运算符.. 缺省取址运算符.. 缺省取址运算符 const. 注意:有些书上只是简单的介绍了前 ...
- validator验证
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xht ...
- Python基础篇-day3
主要内容:字典 集合 文件处理 字符编码 1.字典dict简介dict就是key value值,索引有意义,数据无序 key定义规则:a:不可变--数字.字符串.元组(可变--列表.字典)b:不能重复 ...