【CodeForces - 735A 】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 kcells 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.

Input

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.

Output

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).

Examples

Input

5 2
#G#T#

Output

YES

Input

6 1
T....G

Output

YES

Input

7 3
T..#..G

Output

NO

Input

6 2
..GT..

Output

NO

Note

In the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4.

In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left 5 times.

In the third sample, the grasshopper can't make a single jump.

In the fourth sample, the grasshopper can only jump to the cells with odd indices, thus he won't be able to reach the insect.

解题报告:

  有点简单,直接模拟、

AC代码:

#include<bits/stdc++.h>using namespace std;int main() {int n,k,st,ed,flag = 0;;cin>>n>>k;char s[105];scanf("%s",s);for(int i = 0; i<n; i++) {if(s[i] == 'G') st = i,flag = 1;if(s[i] == 'T') ed = i,flag = 2;}if(abs(st-ed) % k != 0) {printf("NO\n");return 0 ;}if(st > ed) swap(st,ed);for(int i = st; i<=ed; i+=k) {if(s[i] == '#') {printf("NO\n");return 0 ;}}printf("YES\n");return 0 ;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441717.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

java私有成员的访问_java – 使用私有成员或公共访问器的方法

我意识到这可能无法回答,但我正在寻找是否有关于是否直接使用私有成员或类方法中的公共访问器的某种指导.例如,考虑以下代码(在Java中,但在C中看起来非常相似)&#xff1a;public class Matrix {// Private Membersprivate int[][] e;private int numRows;private int numCols;…

☆【CodeForces - 764C】Timofey and a tree (思维题,树的性质)

题干&#xff1a; Each New Year Timofey and his friends cut down a tree of n vertices and bring it home. After that they paint all the n its vertices, so that the i-th vertex gets color ci. Now its time for Timofey birthday, and his mother asked him to re…

java中实现线程互斥的关键词_简单的互斥同步方式——synchronized关键字详解

2. synchronized的原理和实现细节2.1 synchronized可以用在那些地方静态方法,锁对象为当前类的class对象,不用显式指定实例方法,锁对象为当前实例对象,不用显式指定同步代码块,锁对象为括号中指定的对象&#xff0c;必须显式指定被synchronized修饰的方法或者代码块,同一时刻只…

【51nod - 1875】 丢手绢(约瑟夫问题,可打表,用STL模拟)

题干&#xff1a; 六一儿童节到了&#xff0c;小朋友们在玩丢手绢的游戏。总共有C个小朋友&#xff0c;编号从1到C&#xff0c;他们站成一个圈&#xff0c;第i(1<i<C)个人的左边是i-1&#xff0c;第1个人的左边是C。第i(1<i<C)个人的右边是i1&#xff0c;第C个人的…

mysql server远程连接_本地远程连接 MySQL server

问题MySql Server 出于安全方面考虑默认只允许本机(localhost, 127.0.0.1)来连接访问。如果想远程访问&#xff0c;需要额外做下操作。配置修改定位文件/etc/mysql/mysql.conf.d/mysqld.cnf定位属性skip-networking #注释掉 因为它是屏蔽掉一切TCP/IP连接bind-address 127.0.0…

关闭VS警告#pragma warning(disable:4996)

代码实现&#xff1a; #pragma warning(disable:4996) 1. #pragma warning只对当前文件有效&#xff08;对于.h&#xff0c;对包含它的cpp也是有效的&#xff09;&#xff0c;而不是对整个工程的所有文件有效。当该文件编译结束&#xff0c;设置也就失去作用。 2. #pragma wa…

【CodeForces - 608C】Chain Reaction (二分 或 dp ,思维)

题干&#xff1a; 题目大意&#xff1a; 题意是在一条直线上坐落着不同位置的灯塔&#xff0c;每一个灯塔有自己的power level&#xff0c;当作是射程范围。现在从最右边的灯塔开始激发&#xff0c;如果左边的灯塔在这个灯塔的范围之内&#xff0c;那么将会被毁灭。否则会被激…

java关闭文本_如何更优雅的关闭java文本、网络等资源

通常在 java 中对文本、网络资源等操作起来是很繁杂的&#xff0c;要声明&#xff0c;读取&#xff0c;关闭三个阶段&#xff0c;还得考虑异常情况。假设我们要读取一段文本显示到控制台&#xff0c;通常会有如下的代码&#xff1a;public static void main(String[] args) {Fi…

java类匿名类实例_Java匿名类,匿名内部类实例分析

本文实例讲述了Java匿名类&#xff0c;匿名内部类。分享给大家供大家参考&#xff0c;具体如下&#xff1a;本文内容&#xff1a;内部类匿名类首发日期 &#xff1a;2018-03-25内部类&#xff1a;在一个类中定义另一个类&#xff0c;这样定义的类称为内部类。【包含内部类的类可…

【HDU - 6441】Find Integer (费马大定理 + 奇偶数列法构造勾股定理)

题干&#xff1a; people in USSS love math very much, and there is a famous math problem . give you two integers nn,aa,you are required to find 22 integers bb,cc such that ananbncnbncn. Input one line contains one integer TT;(1≤T≤1000000)(1≤T≤100000…

dart与java互调_Dart与Java不同的地方

数据类型基类是num数值型的操作运算符&#xff1a; 、 - 、* 、/ 、 ~/ 、 %/ 除法 整数余数~/ 除法 取整% 取余常用属性&#xff1a; isNaN、isEven、isOdd (是否非数字、奇偶)常用方法&#xff1a;abs()、round()、floorl()、ceil()、toInt()、toDouble()double nan 0.0 / 0…

算法学习 母函数

母函数又称生成函数。定义是给出序列:a0,a1,a2,.......ak,......,那么函数G(x)a0a1*xa2*x2......ak*xk称为序列a0,a1,a2,.......ak,......的母函数(即生成函数)。 例如&#xff1a;序列1,2,3.......n的生成函数为&#xff1a;G(x)x2x23x3........nxn。点此链接:百度百科 特别…

plsq卸载 删除注册表、_win10操作系统下oracle11g客户端/服务端的下载安装配置卸载总结...

win10操作系统下oracle11g客户端/服务端的下载安装配置卸载总结一&#xff1a;前提注意&#xff1a;现在有两种安装的方式1. oracle11g服务端(64位)oracle客户端(32位)plsql(32位)2. oracle11g服务端(32位)plsql(32位)这里我选择的是第二种 原因是 &#xff1a;首先需要明确ora…

【HDU -1568】 Fibonacci(斐波那契通项公式+取对数)

Fibonacci Problem Description 2007年到来了。经过2006年一年的修炼&#xff0c;数学神童zouyu终于把0到100000000的Fibonacci数列 (f[0]0,f[1]1;f[i] f[i-1]f[i-2](i>2))的值全部给背了下来。 接下来&#xff0c;CodeStar决定要考考他&#xff0c;于是每问他一个数字&a…

java sqlserver分页查询_实现sqlserver分页查询语句

实现sqlserver分页查询语句sqlServer&#xff1a;一次查询&#xff0c;数据库只返回一页的数据。而不是取出所有的数据。pagesize&#xff1a; 每页显示记录数cureentpage&#xff1a;当前页数select * from ( select TOP pagesize * from ( SELECT TOP pagesize*cureentpage…

【HDU - 1269】迷宫城堡 (tarjan算法模板)

题干&#xff1a; 为了训练小希的方向感&#xff0c;Gardon建立了一座大城堡&#xff0c;里面有N个房间(N<10000)和M条通道(M<100000)&#xff0c;每个通道都是单向的&#xff0c;就是说若称某通道连通了A房间和B房间&#xff0c;只说明可以通过这个通道由A房间到达B房间…

php5.4 curl,PHP5.0~5.6 各版本兼容性cURL文件上传功能实例分析

本文实例分析了PHP5.0~5.6 各版本兼容性cURL文件上传功能。分享给大家供大家参考&#xff0c;具体如下&#xff1a;最近做的一个需求&#xff0c;要通过PHP调用cURL&#xff0c;以multipart/form-data格式上传文件。踩坑若干&#xff0c;够一篇文章了。重要警告没事不要读PHP的…

【HDU - 1518】Square (经典的dfs + 剪枝)

题干&#xff1a; Given a set of sticks of various lengths, is it possible to join them end-to-end to form a square? Input The first line of input contains N, the number of test cases. Each test case begins with an integer 4 < M < 20, the number …

php发扑克牌,php 扑克牌代码的简单例子

本文分享下&#xff0c;一段可模拟扑克牌玩法的php代码&#xff0c;有需要的朋友参考下。php 扑克牌代码&#xff0c;如下&#xff1a;cut();* www: jbxue.com*/class cards{/**** Declare our deck variable**/private $deck;/**** Constructor.. duh!**/function __construct…

【HDU - 1026 】Ignatius and the Princess I (bfs + 记录路径)

题干&#xff1a; The Princess has been abducted by the BEelzebub feng5166, our hero Ignatius has to rescue our pretty Princess. Now he gets into feng5166s castle. The castle is a large labyrinth. To make the problem simply, we assume the labyrinth is a N*…