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. 如何在java中发起http和https请求

    一般调用外部接口会需要用到http和https请求. 一.发起http请求 1.写http请求方法 //处理http请求 requestUrl为请求地址 requestMethod请求方式,值为&qu ...

  2. zabbix3.2的server和zabbix-agent2.2怎么监控MySQL的办法

    zabbix官方支持监控MySQL,但直接使用默认的模板是不可用的,还需要经过额外的设置才可以使用.如果只需要对mysql数据库做简单的监控,zabbix自带的模板完全能够满足要求:如果有更高的需求那 ...

  3. KEGG数据库介绍

    转载自https://mp.weixin.qq.com/s/pqbMXMkuqEXbLf31PTxGZQ KEGG简介 KEGG 数据库于 1995 年由 Kanehisa Laboratories ...

  4. Structs配置文件 zg项目介绍

    Structs配置文件 1.以系统代码为名称 例:

  5. oracle存储过程-获取错误信息

    dbms_output.put_line('code:' || sqlcode); dbms_output.put_line('errm:' || sqlerrm); dbms_output.put_ ...

  6. pidgin的未认证解决办法

    安全验证打开还是无法登陆,并且手机无法验证. 解决:开启手机二次验证,给pidgin设置专门的登陆账户密码,即可解决.

  7. hdoj1074--Doing Homework (DP 状态压缩)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1074 思路: 看着数据很小,15,但是完成的顺序有15!情况,这么大的数据是无法实现的.上网查才知道要 ...

  8. 在java中使用ffmpeg将amr格式的语音转为mp3格式

    ffmpeg是一个非常强大的音视频处理工具,官网是:http://ffmpeg.org/. 由于ffmpeg在windows上和linux系统上的执行文件不一样(Windows上不需要安装ffmpeg ...

  9. volatile是否就是原子性/线程同步的

    在java线程并发处理中,有一个关键字volatile的使用目前存在很大的混淆,以为使用这个关键字,在进行多线程并发处理的时候就可以万事大吉. Java语言是支持多线程的,为了解决线程并发的问题,在语 ...

  10. 构建openssl debug版

    一.简介 作为一种安全协议,openssl囊括了主要的密码算法.常用的密钥和证书封装管理功能以及SSL协议,并提供了丰富的应用程序供测试或其它目的使用. 参考: http://www.linuxidc ...