codeforces 500A. New Year Transportation
题目链接: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的更多相关文章
- Codeforces 500A - New Year Transportation【DFS】
题意:给出n个数,终点t 从第i点能够跳到i+a[i],问能否到达终点 #include<iostream> #include<cstdio> #include<cstr ...
- 【codeforces 724E】Goods transportation
[题目链接]:http://codeforces.com/problemset/problem/724/E [题意] 有n个城市; 这个些城市每个城市有pi单位的物品; 然后已知每个城市能卖掉si单位 ...
- Codeforces 724 E Goods transportation
Description 有 \(n\) 个点,每个点有一个入流和出流,每个点与编号比它大的点连边,容量为 \(c\) ,求最大流. Sol DP. 这种特殊的图可以DP,把最大流转化成最小割. 最小割 ...
- 专题:CF图论杂题
题目是来自HZW的博客(构造题我是各种不会...) Solved 1 / 1 A CodeForces 500A New Year Transportation Solved 1 / 1 B Code ...
- 树&图 记录
A - Lake Counting POJ - 2386 最最最最最基础的dfs 挂这道题为了提高AC率(糖水不等式 B - Paint it really, really dark gray Cod ...
- CodeForces 500 A. New Year Transportation
Description New Year is coming in Line World! In this world, there are n cells numbered by integers ...
- 【最大流】ECNA 2015 F Transportation Delegation (Codeforces GYM 100825)
题目链接: http://codeforces.com/gym/100825 题目大意: N(N<=600)个点,每个点有个名字Si,R(R<=200)个生产商在R个点上,F(F<= ...
- Codeforces 724E Goods transportation(最小割转DP)
[题目链接] http://codeforces.com/problemset/problem/724/E [题目大意] 每个城市有pi的物品可以运出去卖,si个物品可以买, 编号小的城市可以往编号大 ...
- 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, ...
随机推荐
- oracle 中的round()函数、null值,rownum
round()函数:四舍五入函数 传回一个数值,该数值按照指定精度进行四舍五入运算的结果. 语法:round(number[,decimals]) Number:待处理的函数 Decimals:精度, ...
- PHP基础 mysqli的事务处理
1: <?php 2: // PHP 的mysqli的事务处理 3: //======================================================== 4: ...
- 【codevs1380】没有上司的舞会
题目描述 Ural大学有N个职员,编号为1~N.他们有从属关系,也就是说他们的关系就像一棵以校长为根的树,父结点就是子结点的直接上司.每个职员有一个快乐指数.现在有个周年庆宴会,要求与会职员的快乐指数 ...
- struts2-(2)HelloWorld
1.环境配置 1).进入http://struts.apache.org/download.cgi#struts23241 下载 struts官方源码 2).解压,进入apps/struts2-bla ...
- 如何在IE8设置透明背景
background:rgba(0,0,0,0.5);filter: progid:DXImageTransform.Microsoft.gradient(startcolorstr=#7F00000 ...
- js刷新页面的几种方法
history.go(0) location.reload() location=location location.assign(location) document.execCommand('Re ...
- centos 设置永久dns
最近在折腾一个问题. 由于服务器的带宽是联通5M, 不稳定.而且所处的网络的dns解析貌似老出问题,每隔一定周期解析时间特别长. 于是乎,想在本地做一个dns,这样可以减少dns解析时间,并做些静态配 ...
- tornado + supervisor + nginx 的一点记录
看了比较多的blog基本都是这个架构: supervisor ------------ app1 |-------app2 |-------.... |-------appn |-------ngin ...
- python项目在windows下运行出现编码错误的解法
在启动文件里面加入 import sysreload(sys) sys.setdefaultencoding('GB2312') 这样在windows下调试运行神马的,就不会报错了. 当然发布时,建议 ...
- extjs动态改变样式
{ width:438, height:440, name:'loginDiv', ui:'123', x: '50%' , y: 200, border:true, bodyStyle:{ 'bor ...