博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #382 (Div. 2) A. Ostap and Grasshopper bfs
阅读量:6533 次
发布时间:2019-06-24

本文共 2170 字,大约阅读时间需要 7 分钟。

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
using namespace std;const int maxn = 1e2+7;string s;int vis[maxn],st,n,ed,k;int main(){ queue
Q; cin>>n>>k; cin>>s; for(int i=0;i
=0&&vis[now-k]==0&&s[now-k]!='#') Q.push(now-k); } if(vis[ed])cout<<"YES"<

转载地址:http://iiqbo.baihongyu.com/

你可能感兴趣的文章
两列布局(浮动、定位、flex)和三列布局(圣杯、双飞翼、flex)
查看>>
Python2.6升级2.7
查看>>
作业九 二维数组
查看>>
在web.xml中配置jsp-config实现jsp自动导入
查看>>
第115天:Ajax 中artTemplate模板引擎(一)
查看>>
PXE+Kickstart无人值守安装系统re
查看>>
Python之Mysql及SQLAlchemy操作总结
查看>>
OCM_第二十天课程:Section9 —》Data Guard _ DATA GUARD 搭建/DATA GUARD 管理
查看>>
PM如何突破工程师心防
查看>>
Linux ACL管理详解
查看>>
MySQL主从复制备份
查看>>
CSS属性
查看>>
MVC中<%=%>和<%:%>区别
查看>>
mac系统终端的color scheme配置和vim配置
查看>>
windows server2008 r2修改远程桌面连接端口。
查看>>
NodeJS学习笔记-创建Web服务
查看>>
UOJ 347(洛谷4220) 【WC2018】通道——随机化
查看>>
POJ1179 Polygon
查看>>
Word Break
查看>>
整理收藏一份PHP高级工程师的笔试题
查看>>