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 ...
随机推荐
- spring ioc 注解配置
要注意spring 版本与jdk的兼容性 applicationContext-resource.xml: <beans xmlns="http://www.springframewo ...
- hadoop无法启动常见原因
1.Could not chdir to home directory /home/USER: Permission denied 启动datanode时会报这个错误,尝试利用ssh登录datanod ...
- IDEA kotlin 配置
修改 idea 安装目录 bin 目录 下 idea.properties 文件修改idea.max.intellisense.filesize=50000 避免proto 生成的java文件不被 ...
- Android使用HTTPS进行IP直连握手失败问题(okHttp)
为什么要使用ip直连这种方式去请求我们的服务器呢?这其实和国内运营伤有关,运营商有时为了利益会将你的域名劫持换成他人的域名,为了防止这种情况的发生通用的解决办法要么联系运营商要么就只能使用ip直连了. ...
- e.g.-basic-Si
! Band structure of silicon. The points listed after plot1d below are the ! vertices joined in the b ...
- Intersection of Two Linked Lists(LIST-2 POINTER)
Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...
- Segments(叉积)
Segments http://poj.org/problem?id=3304 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: ...
- 使用一般处理程序(IHttpHandler)制作图片水印
做网站的时候经常需要将图片加上网站名称的水印.这样做可以使别人转载图片的时候出现图片出处 ,利于网站宣传.但是如果利用ps来一个一个加水印工作量非常浩大,而且修改了之后就没法还原.这 篇教程教大家利用 ...
- 批量MD5命名文件
#coding=utf-8 import os import hashlib def GetFileMd5(filename): if not os.path.isfile(filename): pr ...
- ubuntu 安装 google Gtest
1.安装源代码 在ubuntu的桌面上,右键选择打开终端,在终端中输入如下命令: $ sudo apt-get install libgtest-dev 下载源码后,apt将会在目录/usr/src/ ...