A. Ostap and Grasshopper

题面

On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length n such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The grasshopper wants to eat the insect.

Ostap knows that grasshopper is able to jump to any empty cell that is exactly k cells away from the current (to the left or to the right). Note that it doesn't matter whether intermediate cells are empty or not as the grasshopper makes a jump over them. For example, if k = 1 the grasshopper can jump to a neighboring cell only, and if k = 2 the grasshopper can jump over a single cell.

Your goal is to determine whether there is a sequence of jumps such that grasshopper will get from his initial position to the cell with an insect.

输入

The first line of the input contains two integers n and k (2 ≤ n ≤ 100, 1 ≤ k ≤ n - 1) — the number of cells in the line and the length of one grasshopper's jump.

The second line contains a string of length n consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the corresponding cell is empty, character '#' means that the corresponding cell contains an obstacle and grasshopper can't jump there. Character 'G' means that the grasshopper starts at this position and, finally, 'T' means that the target insect is located at this cell. It's guaranteed that characters 'G' and 'T' appear in this line exactly once.

输出

If there exists a sequence of jumps (each jump of length k), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes).

样例输入

5 2

G#T#

样例输出

YES

题意

给你一个长度为n的字符串,G是起点,T是终点,现在你每步要走距离为k,现在问你能否从G走到T。

题解

直接暴力bfs好了

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e2+7;
string s;
int vis[maxn],st,n,ed,k;
int main()
{
queue<int>Q;
cin>>n>>k;
cin>>s;
for(int i=0;i<s.size();i++)
if(s[i]=='G')st=i;
else if(s[i]=='T')ed=i;
Q.push(st);
while(!Q.empty()){
int now=Q.front();
Q.pop();
if(vis[now])continue;
vis[now]=1;
if(now+k<s.size()&&vis[now+k]==0&&s[now+k]!='#')
Q.push(now+k);
if(now-k>=0&&vis[now-k]==0&&s[now-k]!='#')
Q.push(now-k);
}
if(vis[ed])cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}

Codeforces Round #382 (Div. 2) A. Ostap and Grasshopper bfs的更多相关文章

  1. Codeforces Round #382 (Div. 2)E. Ostap and Tree

    E. Ostap and Tree time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  2. Codeforces Round #382 (Div. 2) 继续python作死 含树形DP

    A - Ostap and Grasshopper zz题能不能跳到  每次只能跳K步 不能跳到# 问能不能T-G  随便跳跳就可以了  第一次居然跳越界0.0  傻子哦  WA1 n,k = map ...

  3. Codeforces Round #382 (Div. 2) (模拟|数学)

    题目链接: A:Ostap and Grasshopper B:Urbanization C:Tennis Championship D:Taxes 分析:这场第一二题模拟,三四题数学题 A. 直接模 ...

  4. Codeforces Round #382 (Div. 2) D. Taxes 哥德巴赫猜想

    D. Taxes 题目链接 http://codeforces.com/contest/735/problem/D 题面 Mr. Funt now lives in a country with a ...

  5. Codeforces Round #382 (Div. 2)C. Tennis Championship 动态规划

    C. Tennis Championship 题目链接 http://codeforces.com/contest/735/problem/C 题面 Famous Brazil city Rio de ...

  6. Codeforces Round #382 (Div. 2)B. Urbanization 贪心

    B. Urbanization 题目链接 http://codeforces.com/contest/735/problem/B 题面 Local authorities have heard a l ...

  7. Codeforces Round #382 Div. 2【数论】

    C. Tennis Championship(递推,斐波那契) 题意:n个人比赛,淘汰制,要求进行比赛双方的胜场数之差小于等于1.问冠军最多能打多少场比赛.题解:因为n太大,感觉是个构造.写写小数据, ...

  8. Codeforces Round #382 (Div. 2) C. Tennis Championship 斐波那契

    C. Tennis Championship time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  9. Codeforces Round #382 (Div. 2) D. Taxes 歌德巴赫猜想

    题目链接:Taxes D. Taxes time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

随机推荐

  1. git的一些指令

    1.这是一篇git.github相关具体操作的连接 http://www.cnblogs.com/fanyong/p/3424501.html 2. git remote -v 查看远程分支 git ...

  2. IOS封装一个微信聊天的输入工具

    1.实现微信的输入工具 实现了大部分功能,各模块实现的很清晰,有利于更好的二次开发(适合自己的需求),我自己总结出来的, 可以更快的让你实现输入工具,不需要扩展的也可以很方便的使用这个输入工具. 1) ...

  3. Unix常用指令

    pwd 表示获取自己当前所在位置 ls 表示查看当前文件夹中的内容 cd 进入指定目录 mkdir  文件夹1 创建一个文件夹名为文件夹1的文件夹 rmdir  文件夹2 删除一个文件夹名为文件夹2的 ...

  4. Rtp 协议实现网络广播台网络收音机

    RTP协议介绍:http://www.360doc.com/content/11/1009/15/496343_154624612.shtml 本文中使用了 StreamCoders 的 RTP.ne ...

  5. 作死遇到的坑--view向下偏移

    好大一个坑.--谈谈view偏移问题: 先上张图, 图中白色部分.上面的是从网上找的资源.将导航栏隐藏之后用collectionView加上去而实现的滑动标签功能.开始以为是代码中的问题.然后仔细推敲 ...

  6. innodb_ft_max_token_size取值范围

    根据问档中所说,innodb_ft_max_token_size取值范围为10-252,而实际上但我们在配置文件设置innodb_ft_max_token_size=252时,error log会出现 ...

  7. 使用jsPlumb制作流程图设计器

    jsPlumb是一个比较强大的绘图组件,它提供了一种方法,主要用于连接网页上的元素.在现代浏览器中,它使用SVG或者Canvas技术,而对于IE8以下(含IE8)的古董浏览器,则使用VML技术. 项目 ...

  8. 使用 New Relic 监控接口服务性能

    偶然看到贴子在使用[Rails API] 使用这个APM监控,今天试了下.NET IIS环境下,配置一路NEXT即可. 主要指标 服务响应时间 Segment SQL执行时间 安全问题 1.走HTTP ...

  9. JS自动化

    写在前面 记得当时刷笔试题的时候有了解过“前端工程化”,无非就是用自动化工具帮助开发人员完成一些小细节,提高工作效率之类的,不过当时可没想到可维护性这么远 构建项目 -> 模块化开发 -> ...

  10. 冲刺阶段 day 8

    项目进展:教师部分包括教师所属系别.工号.姓名.性别.电话.邮箱.地址.我们已经基本完成窗体的构建和代码编写.可以实现教师信息的增加查询. 代码如下: using System; using Syst ...