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 ...
随机推荐
- 使用Assetbundle时可能遇到的坑
原地址:http://www.cnblogs.com/realtimepixels/p/3652128.html 一 24 十一郎未分类 No Comments 转自 http://www.unity ...
- 远程数据源Combobox
Ext.define('bookInfo', { extend: 'Ext.data.Model',//新类继承自model fields: [{ name: 'b ...
- 客户端的数据来源:QueryString, Form, Cookie Request[]与Request.Params[]
在ASP.NET编程中,有三个比较常见的来自于客户端的数据来源:QueryString, Form, Cookie . 我们可以在HttpRequest中访问这三大对象. QueryString: 获 ...
- 线性时间常数空间找到数组中数目超过n/5的所有元素
问题描述: Design an algorithm that, given a list of n elements in an array, finds all the elements that ...
- c# string.Format用法总结
文章出处:http://www.cnblogs.com/7788/archive/2009/05/13/1455920.html 先举几个简单的应用案例: 1.格式化货币(跟系统的环境有关,中文系统默 ...
- 14个Xcode中常用的快捷键操作
在Xcode 6中有许多快捷键的设定可以使得你的编程工作更为高效,对于在代码文件中快速导航.定位Bug以及新增应用特性都是极有效的. 当然,你戳进这篇文章的目的也在于想要快速的对代码文件进行操作,或者 ...
- Apache设置禁止访问网站目录(目录列表显示文件)
默认apache在当前目录下没有index.html入口就会显示目录.让目录暴露在外面是非常危险的事,如下操作禁止apache显示目录,希望文章对各位有帮助. 进入apache的配置文件 httpd. ...
- ExtJs之Ext.util.ClickRepeater
<!DOCTYPE html> <html> <head> <title>ExtJs</title> <meta http-equiv ...
- EOF的一点注记
int ch; while( (ch = getchar()) != EOF ) { putchar(ch); } 执行程序,输入:we are the,然后回车.运行结果如下: [purple@lo ...
- 今天来做一个PHP电影小爬虫。
今天来做一个PHP电影小爬虫.我们来利用simple_html_dom的采集数据实例,这是一个PHP的库,上手很容易.simple_html_dom 可以很好的帮助我们利用php解析html文档.通过 ...