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, ...
随机推荐
- 清空mysql表后,自增id复原
alter table `ajy_servercategory` AUTO_INCREMENT=1; alter table `Table_Name` AUTO_INCREMENT=n; 一.清除my ...
- 使用fiddler手机抓包
Fiddler不但能截获各种浏览器发出的HTTP请求, 也可以截获各种智能手机发出的HTTP/HTTPS请求. Fiddler能捕获IOS设备发出的请求,比如IPhone, IPad, MacBook ...
- [Linux] Chang DNS Setting on Linux
主机的虚拟机使用 NAT 模式时, NAT的DNS不好用.于是需要将虚拟机的DNS改成和主机的一样,这样虚拟机也可以请求互联网资源. Linux的DNS 服务器定义在 /etc/resolv.conf
- R语言 recommenderlab 包
recommend li_volleyball 2016年3月20日 library(recommenderlab) ## Warning: package 'recommenderlab' was ...
- eclipse svn快捷键
一.打开eclipse插件安装市场,搜索svn,选择Subclipse安装 二.设置 svn ,设置快捷键, 1.windows-preference,在打开对话框输入keys过滤出keys选择 2. ...
- poj.1703.Find them, Catch them(并查集)
Find them, Catch them Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I6 ...
- SparkSql 不支持Date Format (支持Timestamp)
最近项目中需要用到sparksql ,需要查询sql Date类型, 无奈,官方现阶段 1.6.0 还不支持Date类型,不过支持Timestamp类型,所以问题可以解决了. 1.解析 SimpleD ...
- httpd-2.2 配置及用法完全攻略
导读 apache是一款稳定的流行的web软件,是linux操作系统中默认的web管理软件.在RHEL/Centos系列中可以用rpm直接进行安装,服务名为httpd.apache有很多设置和调优 的 ...
- Unity手游之路<二>Java版服务端使用protostuff简化protobuf开发
http://blog.csdn.net/janeky/article/details/17151465 开发一款网络游戏,首先要考虑的是客户端服务端之间用何种编码格式进行通信.之前我们介绍了Unit ...
- 导航栏的坑 (导航透明/导航除线/titleIView)
//以下四个条件缺一不可 /.必须是半透明状态 self.navigationBar.translucent = YES; //2.导航栏背景图片为空图片 (不可以设置backgroundColor或 ...