Codeforces 500A - New Year Transportation【DFS】
题意:给出n个数,终点t
从第i点能够跳到i+a[i],问能否到达终点
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
#define mod=1e9+7;
using namespace std; typedef long long LL;
const int INF = 0x7fffffff;
const int maxn=;
int a[maxn],vis[maxn];
int n,t;
int flag=; void dfs(int x){
if(vis[x]) return;
vis[x]=;
int xx=x+a[x];
if(xx==t){
flag=;
return;
}
dfs(xx);
} int main(){
scanf("%d %d",&n,&t);
memset(vis,,sizeof(vis));
for(int i=;i<n;i++) scanf("%d",&a[i]);
dfs();
if(flag) printf("YES\n");
else printf("NO\n");
return ;
}
Codeforces 500A - New Year Transportation【DFS】的更多相关文章
- Codeforces 653B Bear and Compressing【DFS】
题目链接: http://codeforces.com/problemset/problem/653/B 题意: 要求你构造一个长度为n的字符串使得通过使用m个操作,最终获得字符a.已知第i个操作将字 ...
- codeforces 277 A Learning Languages 【DFS 】
n个人,每个人会一些语言,两个人只要有会一门相同的语言就可以交流,问为了让这n个人都交流,至少还得学多少门语言 先根据n个人之间他们会的语言,建边 再dfs找出有多少个联通块ans,再加ans-1条边 ...
- 【第40套模拟题】【noip2011_mayan】解题报告【map】【数论】【dfs】
目录:1.潜伏者 [map] 2.Hankson的趣味题[数论]3.mayan游戏[dfs] 题目: 1. 潜伏者(spy.pas/c/cpp)[问题描述]R 国和S 国正陷入战火之中,双方都互派间谍 ...
- Kattis - glitchbot 【DFS】
Kattis - glitchbot [DFS] 题意 有一个机器人 刚开始在(0, 0),然后给出一个目标点,并且会给出一系列指令,但是其中会有一个指令是错误的.我们需要找出那个指令,并且改成正确的 ...
- HDU 6113 度度熊的01世界 【DFS】(2017"百度之星"程序设计大赛 - 初赛(A))
度度熊的01世界 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- [CodeForces - 1225E]Rock Is Push 【dp】【前缀和】
[CodeForces - 1225E]Rock Is Push [dp][前缀和] 标签:题解 codeforces题解 dp 前缀和 题目描述 Time limit 2000 ms Memory ...
- 【dfs】codeforces Journey
http://codeforces.com/contest/839/problem/C [AC] #include<iostream> #include<cstdio> #in ...
- 【DFS】codeforces B. Sagheer, the Hausmeister
http://codeforces.com/contest/812/problem/B [题意] 有一个n*m的棋盘,每个小格子有0或1两种状态,现在要把所有的1都变成0,问最少的步数是多少?初始位置 ...
- Codeforces 716B Complete the Word【模拟】 (Codeforces Round #372 (Div. 2))
B. Complete the Word time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
随机推荐
- samsung-smart app 开发
http://www.samsungdforum.com/ http://seller.samsungapps.com/login/signIn.as?returnURL=%2fmain%2fsell ...
- HDU 2674 N!Again(数学思维水题)
题目 //行开始看被吓一跳,那么大,没有头绪, //看了解题报告,发现这是一道大大大的水题,,,,,//2009 = 7 * 7 * 41//对2009分解,看它有哪些质因子,它最大的质因子是41,那 ...
- 整数划分 Integer Partition(二)
本文是整数划分的第二节,主要介绍整数划分的一些性质. 一 先来弥补一下上一篇文章的遗留问题:要求我们所取的 (n=m1+m2+...+mi )中 m1 m2 ... mi连续,比如5=1+4就不符合 ...
- POJ 2531 Network Saboteur (枚举+剪枝)
题意:给你一个图,图中点之间会有边权,现在问题是把图分成两部分,使得两部分之间边权之和最大. 目前我所知道的有四种做法: 方法一:状态压缩 #include <iostream> #inc ...
- 如何提高SQL的执行效率
一.因情制宜,建立“适当”的索引 建立“适当”的索引是实现查询优化的首要前提. 索引(index)是除表之外另一重要的.用户定义的存储在物理介质上的数据结构.当根据索引码的值搜索数据时,索引提供了对数 ...
- Eclipse导入工程中文乱码问题
此文引用自eclipse导入工程中文乱码问题,作者elleniou. 关于Eclipse导入工程中文乱码问题实在是一个非常令人头疼的,深感一定要彻底解决才算放心,故摘抄上文如下: eclipse之所以 ...
- C#加密算法汇总
方法一: //须添加对System.Web的引用 using System.Web.Security; ... /// <summary> /// SHA1加密字符串 /// </s ...
- Android Non-UI to UI Thread Communications(Part 3 of 5)
Original:http://www.intertech.com/Blog/android-non-ui-to-ui-thread-communications-part-3-of-5/ Conti ...
- http://www.cnblogs.com/yjmyzz/p/dubbox-demo.html
http://www.cnblogs.com/yjmyzz/p/dubbox-demo.html
- PHP:错误 Deprecated: Function split() is deprecated in ... 解决办法
PHP:错误 Deprecated: Function split() is deprecated in ... 解决办法 PHP5.3 split() 不建议使用的原因:PHP 5.3.0 之后的r ...