Codeforces735A Ostap and Grasshopper 2016-12-13 11:53 78人阅读 评论(0) 收藏
2 seconds
256 megabytes
standard input
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.
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
6 1
T....G
YES
7 3
T..#..G
NO
6 2
..GT..
NO
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) 收藏的更多相关文章
- 8大排序算法图文讲解 分类: Brush Mode 2014-08-18 11:49 78人阅读 评论(0) 收藏
排序算法可以分为内部排序和外部排序,内部排序是数据记录在内存中进行排序,而外部排序是因排序的数据很大,一次不能容纳全部的排序记录,在排序过程中需要访问外存. 常见的内部排序算法有:插入排序.希尔排序. ...
- 团体程序设计天梯赛L2-021 点赞狂魔 2017-04-18 11:39 154人阅读 评论(0) 收藏
L2-021. 点赞狂魔 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 微博上有个"点赞"功能,你可以为你 ...
- 企业证书APP发布流程 分类: ios相关 app相关 2015-06-10 11:01 212人阅读 评论(0) 收藏
企业发布app的 过程比app store 发布的简单多了,没那么多的要求,哈 但是整个工程的要求还是一样,比如各种像素的icon啊 命名规范啊等等. 下面是具体的流程 1.修改你的 bundle i ...
- 用IBM WebSphere DataStage进行数据整合: 第 1 部分 分类: H2_ORACLE 2013-08-23 11:20 688人阅读 评论(0) 收藏
转自:http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0602zhoudp/ 引言 传统的数据整合方式需要大量的手工 ...
- 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 ...
- 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 ...
- 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 ...
- 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 - ...
- 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 ...
随机推荐
- Ubuntu 安装 Zabbix 3.2详细步骤
创建 zabbix 用户 因为zabbix 程序的守护进程需要非特权用户,所以需要创建一个 zabbix 用户,即使从 root 用户启动 zabbix 程序,也会自动切换到 zabbix 用户,所以 ...
- cmd 获取 拖拽文件名
1. @echo off & setlocal enableDelayedExpansion set a= set /p a=Please drag your txt file for spl ...
- Egit的merge合并冲突具体解决方法
稍微总结下弄了半个下午的egit的merge合并冲突解决方法,网上看的都是一个模板出来的,看的糊里糊涂,花了很多时间去实验整个合并流程.. 前提工作 创建一个普通JAVA工程Test,创建一个类Tes ...
- SQL查询效率where语句条件
有索引的列优先,都有索引的看查询出来的数据量,少的优先 in ,not in,<>,is null,is not null 等由于不会走索引,尽量不要使用. WHERE子句后面的条件顺序对 ...
- python版本安装
目的 本文目的在于,对于不熟悉Python的人,教你: 1. 从哪里找到 可以下载到 各种版本的 包括Python 2.x和Python 3.x的 最新版本的 Python. 高手请无视之. 2.以及 ...
- 单词拆分 I · Word Break
[抄题]: 给出一个字符串s和一个词典,判断字符串s是否可以被空格切分成一个或多个出现在字典中的单词. s = "lintcode" dict = ["lint" ...
- discuz的css处理机制
common/common.css 是一个通用的css文件. common/module.css 是某个功能模块使用的css文件. module.css中,利用特殊语法: /** 标识 **/ c ...
- yii2中的rules 自定义验证规则详解
yii2的一个强大之处之一就是他的Form组件,既方便又安全.有些小伙伴感觉用yii一段时间了,好嘛,除了比tp"难懂"好像啥都没有. 领导安排搞一个注册的功能,这家伙刷刷刷的又是 ...
- advance shading--BRDF
其实,双向反射(reflect)分布函数(BRDF)是一个四元函数,这个函数最终只是计算一个比值,这个值确定了射入物体表面的光中有多少被物体表面反射,并最终被眼睛所看到.反射的愈多,眼睛收到的光强越大 ...
- [BAT]win7下用批处理脚本自动删除7天以前创建的文件
set JmeterPath=D:\apache-jmeter-2.7 forfiles /p %JmeterPath%\extras /m *.html -d -7 /c "cmd /c ...