A. King of Thieves
2016-01-28 17:50
176 查看
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
In this problem you will meet the simplified model of game King of Thieves.
In a new ZeptoLab game called "King of Thieves" your aim is to reach a chest with gold by controlling your character, avoiding traps and obstacles on your way.
An interesting feature of the game is that you can design your own levels that will be available to other players. Let's consider the following simple design of a level.
A dungeon consists of n segments located at a same vertical level, each segment is either a platform that character can stand on, or
a pit with a trap that makes player lose if he falls into it. All segments have the same length, platforms on the scheme of the level are represented as '*' and
pits are represented as '.'.
One of things that affects speedrun characteristics of the level is a possibility to perform a series of consecutive jumps of the same length. More formally, when the character is on the platform number i1,
he can make a sequence of jumps through the platforms i1 < i2 < ... < ik,
if i2 - i1 = i3 - i2 = ... = ik - ik - 1.
Of course, all segments i1, i2, ... ikshould
be exactly the platforms, not pits.
Let's call a level to be good if you can perform a sequence of four jumps of the same length or in the other words there must be
a sequence i1, i2, ..., i5,
consisting of five platforms so that the intervals between consecutive platforms are of the same length. Given the scheme of the level, check if it is good.
Input
The first line contains integer n (1 ≤ n ≤ 100)
— the number of segments on the level.
Next line contains the scheme of the level represented as a string of n characters '*' and '.'.
Output
If the level is good, print the word "yes" (without the quotes), otherwise print the word "no" (without
the quotes).
Sample test(s)
input
output
input
output
Note
In the first sample test you may perform a sequence of jumps through platforms 2, 5, 8, 11, 14.
解题说明:此题要求在一个字符串中找到五个“*”,它们之间的间隔相等,可以用暴力枚举来做。
#include<cstdio>
#include <cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
int c, i, j, k, n;
char s[1000];
scanf("%d %s", &n, s);
for(i=1;i<n;i++)
{
for(j=0;j<n;j++)
{
c=0;
for(k=j;k<n;k+=i)
{
if(s[k]=='*')
{
c++;
}
else
{
break;
}
if(c==5)
{
goto end;
}
}
}
}
end:
if(c==5)
{
printf("yes\n");
}
else
{
printf("no\n");
}
return 0;
}
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
In this problem you will meet the simplified model of game King of Thieves.
In a new ZeptoLab game called "King of Thieves" your aim is to reach a chest with gold by controlling your character, avoiding traps and obstacles on your way.
An interesting feature of the game is that you can design your own levels that will be available to other players. Let's consider the following simple design of a level.
A dungeon consists of n segments located at a same vertical level, each segment is either a platform that character can stand on, or
a pit with a trap that makes player lose if he falls into it. All segments have the same length, platforms on the scheme of the level are represented as '*' and
pits are represented as '.'.
One of things that affects speedrun characteristics of the level is a possibility to perform a series of consecutive jumps of the same length. More formally, when the character is on the platform number i1,
he can make a sequence of jumps through the platforms i1 < i2 < ... < ik,
if i2 - i1 = i3 - i2 = ... = ik - ik - 1.
Of course, all segments i1, i2, ... ikshould
be exactly the platforms, not pits.
Let's call a level to be good if you can perform a sequence of four jumps of the same length or in the other words there must be
a sequence i1, i2, ..., i5,
consisting of five platforms so that the intervals between consecutive platforms are of the same length. Given the scheme of the level, check if it is good.
Input
The first line contains integer n (1 ≤ n ≤ 100)
— the number of segments on the level.
Next line contains the scheme of the level represented as a string of n characters '*' and '.'.
Output
If the level is good, print the word "yes" (without the quotes), otherwise print the word "no" (without
the quotes).
Sample test(s)
input
16 .**.*..*.***.**.
output
yes
input
11 .*.*...*.*.
output
no
Note
In the first sample test you may perform a sequence of jumps through platforms 2, 5, 8, 11, 14.
解题说明:此题要求在一个字符串中找到五个“*”,它们之间的间隔相等,可以用暴力枚举来做。
#include<cstdio>
#include <cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
int c, i, j, k, n;
char s[1000];
scanf("%d %s", &n, s);
for(i=1;i<n;i++)
{
for(j=0;j<n;j++)
{
c=0;
for(k=j;k<n;k+=i)
{
if(s[k]=='*')
{
c++;
}
else
{
break;
}
if(c==5)
{
goto end;
}
}
}
}
end:
if(c==5)
{
printf("yes\n");
}
else
{
printf("no\n");
}
return 0;
}
相关文章推荐
- UITextView,Label加载html代码
- AJAX中XMLHttpRequest对象详解(2)
- [工作笔记之一] 转正答辩 2015-08-04 15:08
- ERROR ITMS-90158:
- Simple Java—Strings and Arrays(五)如何在java中有效率的检查一个数组中是否有某值?
- Redis-分片
- open 页面 滚动条
- 快速掌握 Android Studio 中 Gradle 的使用方法
- 将jsp文件打包进jar包内使用
- js和jq的不同方法
- Redis整合Spring结合使用缓存实例
- 学习写接口回调
- leetcode刷题系列C++-Search in Rotated Sorted Array
- MySql――性能优化建议
- HTTP 错误 500.19- Internal Server Error 错误解决方法
- 3-情报搜集
- C#正则获取字符串中的数字
- junit参数化测试
- junit参数化测试
- 最近写机试代码的几点小收获