A. Ostap and Grasshopper
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 nsuch
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 = 1the
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.

_________________________________________________________________________________________________________________

题目的意思是从G走到T,每次G只能走k格,#不能走,.可以走,问能不能走到T

直接找到G的位置,暴力向两边搜过去就好了

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std; int main()
{
char s[1000];
int n,k,x;
while(~scanf("%d%d",&n,&k))
{
scanf("%s",s);
for(int i=0;i<n;i++)
{
if(s[i]=='G')
{
x=i;
break;
}
}
bool fl=0;
for(int i=x;i<n;i+=k)
{
if(s[i]=='#')
{
break;
}
else if(s[i]=='T')
{
fl=1;
break;
}
}
for(int i=x;i>=0;i-=k)
{
if(s[i]=='#')
{
break;
}
else if(s[i]=='T')
{
fl=1;
break;
}
}
if(fl)
printf("YES\n");
else
printf("NO\n"); }
return 0;
}

Codeforces735A Ostap and Grasshopper 2016-12-13 11:53 78人阅读 评论(0) 收藏的更多相关文章

  1. 8大排序算法图文讲解 分类: Brush Mode 2014-08-18 11:49 78人阅读 评论(0) 收藏

    排序算法可以分为内部排序和外部排序,内部排序是数据记录在内存中进行排序,而外部排序是因排序的数据很大,一次不能容纳全部的排序记录,在排序过程中需要访问外存. 常见的内部排序算法有:插入排序.希尔排序. ...

  2. 团体程序设计天梯赛L2-021 点赞狂魔 2017-04-18 11:39 154人阅读 评论(0) 收藏

    L2-021. 点赞狂魔 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 微博上有个"点赞"功能,你可以为你 ...

  3. 企业证书APP发布流程 分类: ios相关 app相关 2015-06-10 11:01 212人阅读 评论(0) 收藏

    企业发布app的 过程比app store 发布的简单多了,没那么多的要求,哈 但是整个工程的要求还是一样,比如各种像素的icon啊 命名规范啊等等. 下面是具体的流程 1.修改你的 bundle i ...

  4. 用IBM WebSphere DataStage进行数据整合: 第 1 部分 分类: H2_ORACLE 2013-08-23 11:20 688人阅读 评论(0) 收藏

    转自:http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0602zhoudp/ 引言 传统的数据整合方式需要大量的手工 ...

  5. Curling 2.0 分类: 搜索 2015-08-09 11:14 3人阅读 评论(0) 收藏

    Curling 2.0 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14289 Accepted: 5962 Descript ...

  6. Codeforces735B Urbanization 2016-12-13 11:58 114人阅读 评论(0) 收藏

    B. Urbanization time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  7. ZOJ1586 QS Network 2017-04-13 11:46 39人阅读 评论(0) 收藏

    QS Network Time Limit: 2 Seconds      Memory Limit: 65536 KB Sunny Cup 2003 - Preliminary Round Apri ...

  8. sqoop 1.4.4-cdh5.1.2快速入门 分类: C_OHTERS 2015-06-06 11:40 208人阅读 评论(0) 收藏

    一.快速入门 (一)下载安装 1.下载并解压 wget http://archive.cloudera.com/cdh5/cdh/5/sqoop-1.4.4-cdh5.1.2.tar.gz tar - ...

  9. HIVE快速入门 分类: B4_HIVE 2015-06-06 11:27 59人阅读 评论(0) 收藏

    (一)简单入门 1.创建一个表 create table if not exists ljh_emp( name string, salary float, gender string) commen ...

随机推荐

  1. 播放一个wav文件

    use mmsystem;SndPlaySound('hello.wav',SND_FILENAME or SND_SYNC) ///////////////////////////////////u ...

  2. 3类与对象——重拾Java

    面向对象编程的3个特性 1 封装性 面向对象编程核心思想之一就是将数据和对数据的操作封装在一起.通过抽象,即从具体的实例中抽取共同的性质形成一般的概念,比如类的概念. 在实际生活中,我们每时每刻都在与 ...

  3. 在windows 2008 R2中SQl Server 2008中代理启动失败的一个原因总结

    启动SQL代理的时候报错如下: 关调用实时(JIT)调试而不是此对话框的详细信息,请参见此消息的结尾. ************** 异常文本 **************System.NullRef ...

  4. oracle ITL(事务槽)的理解

    一.ITL描述: ITL(Interested Transaction List)是Oracle数 据块内部的一个组成部分,位于数据块头(block header),itl由xid,uba,flag, ...

  5. python json5

    install pip install json5 test a.json: { 'a':'b', 'aa':['b1','b2']} =========================== impo ...

  6. ORACLE system表空间满

    解决方法:执行迁移命令,将AUD$表相关移到其它表空间中,也可以新建 一个审计 表空间 / MB DESC) ; alter table aud$ move tablespace SIEBELINDE ...

  7. Realm For Android详细教程

    目录 1.Realm简介 2.环境配置 3.在Application中初始化Realm 4.创建实体 5.增删改查 6.异步操作 7.Demo地址(https://github.com/RaphetS ...

  8. url获取参数

    参考http://www.runoob.com/w3cnote/js-get-url-param.html function getQueryVariable(variable) { var quer ...

  9. 【校招面试 之 C/C++】第7题 C++构造函数不能是虚函数的原因

    1.虚拟函数调用只需要“部分的”信息,即只需要知道函数接口,而不需要对象的具体类型.但是构建一个对象,却必须知道具体的类型信息.如果你调用一个虚拟构造函数,编译器怎么知道你想构建是继承树上的哪种类型呢 ...

  10. IntentService----意图服务

    意图服务是异步进行的  执行完操作后就会自己消毁(onDestroy方法) 本例为点击按钮下载三张图片相当于连续执行三次意图服务中的onStartcommand方法 import android.ap ...