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

题目意思:给出 n-1 个 cell,每个 cell 有一个值 ai,表示在这个编号为 i 的 cell,能到达i + ai 的cell,但不能反过来,即从 i+ai 到达 i 这个 cell。问从第一个cell 开始,是否可以到达 t 这个cell。

  第一次过不了pretest 是因为没有考虑到,如果 t = 1的情况,后来被人 hack 之后就不知道原因了。。。原来是因为第 n 个 cell,默认是 0,应该赋予一个很大的数值!!注意题目只给出 1 ~ n-1 cell 的 ai , 是没有给出 第 n 个的!!!所以要设值,否则代码中的while 会变成死循环的。

  

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std; const int maxn = 3e4 + ; int p[maxn]; int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE
int n, t;
while (scanf("%d%d", &n, &t) != EOF)
{
for (int i = ; i <= n-; i++)
scanf("%d", &p[i]);
p[n] = maxn; // 这个很关键!
bool flag = false;
int i = ;
int step = ; // 初始化为1方便进入while循环的if判断(有可能t==1)
while (step <= n)
{
if (step == t)
{
flag = true;
break;
}
step += p[i];
i = step;
}
printf("%s\n", flag ? "YES" : "NO");
}
return ;
}

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

  1. Codeforces 500A - New Year Transportation【DFS】

    题意:给出n个数,终点t 从第i点能够跳到i+a[i],问能否到达终点 #include<iostream> #include<cstdio> #include<cstr ...

  2. 【codeforces 724E】Goods transportation

    [题目链接]:http://codeforces.com/problemset/problem/724/E [题意] 有n个城市; 这个些城市每个城市有pi单位的物品; 然后已知每个城市能卖掉si单位 ...

  3. Codeforces 724 E Goods transportation

    Description 有 \(n\) 个点,每个点有一个入流和出流,每个点与编号比它大的点连边,容量为 \(c\) ,求最大流. Sol DP. 这种特殊的图可以DP,把最大流转化成最小割. 最小割 ...

  4. 专题:CF图论杂题

    题目是来自HZW的博客(构造题我是各种不会...) Solved 1 / 1 A CodeForces 500A New Year Transportation Solved 1 / 1 B Code ...

  5. 树&图 记录

    A - Lake Counting POJ - 2386 最最最最最基础的dfs 挂这道题为了提高AC率(糖水不等式 B - Paint it really, really dark gray Cod ...

  6. CodeForces 500 A. New Year Transportation

    Description New Year is coming in Line World! In this world, there are n cells numbered by integers ...

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

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

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

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

  9. 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, ...

随机推荐

  1. hdu5072 Coprime (2014鞍山区域赛C题)(数论)

    http://acm.hdu.edu.cn/showproblem.php?pid=5072 题意:给出N个数,求有多少个三元组,满足三个数全部两两互质或全部两两不互质. 题解: http://dty ...

  2. 8-Highcharts曲线图之对数直线图

    <!DOCTYPE> <html lang='en'> <head> <title>8-Highcharts曲线图之对数直线图</title> ...

  3. 如何判断retina,如何判断设备的比例

    http://www.189works.com/article-95647-1.html 说起iPhone 4带来的革新,retina display绝对是最吸引眼球的一项,以至于我现在看电脑的显示屏 ...

  4. 2015年12月01日 GitHub入门学习(一)GitHub简介

    序:Github理念是Social Coding(社会化编程).octocat是它的吉祥物. 一.Github与Git的区别与联系 区别:GIT是仓库,Github是提供一种将代码提交到Git仓库的服 ...

  5. Linux 中常见的命令行,持续更新

    1.添加自己的环境变量 root@adonis:~# echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin r ...

  6. iOS9 Universal Link实现

    先来贴几个比较全面的帖子,看完就差不多了. 1   iOS 9 通用链接(Universal Links) 帖子注意项非常重要,仔细阅读. 自己补充几点: 1 服务器上配置的json文件apple-a ...

  7. Perl 正则表达式

    匹配:m/<regexp>;/ (还可以简写为 /<regexp>;/ ,略去 m)替换:s/<pattern>;/<replacement>;/转化: ...

  8. poj.1988.Cube Stacking(并查集)

    Cube Stacking Time Limit:2000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64u Submi ...

  9. EasyUI中datagrid控件的使用 设置多行表头(两行或多行)

    EasyUI中的datagrid控件十分强大,能生成各种复杂的报表,现在因为项目需要,需要生成一个表头两行的表,找了一些说明文档,以下用一个实例来说明一下: 第一种方法: $('#divData'). ...

  10. php curl 库使用

    支持http basic认证: curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD ...