您的位置:首页 > 其它

Codeforces ZeptoLab Code Rush 2015 A. King of Thieves

2016-07-23 16:41 615 查看




题目大意: 给你一个数字n,第二行给你n个由* .组成的字符串,让你判断给定字符串中是否存在5个位置相距数一样* 如果有输出yes,没有输出no

解题思路:因为题目给定的n是小于等于100的,所以可能用暴力来过。因为要求是5个位置相距一样的*,所以我们可以把给定字符串分为5个部分(因为他们最大相距(n+1)/4),相距超过是不可能形成5个 *。

之后我们可以开两个for循环暴力看它能不能字符串中有没有5个距离一样的*。下面我就上代码吧。。。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <string>
using namespace std;
int n;
char str[105];
bool flag;
int main()
{
while(~scanf("%d",&n))
{
flag=false;
scanf("%s",str);
int cnt=(n+1)>>2;//分成5个部分 因为要求是5个* 他们对应的距离超过cnt就不可能形成5个距离一样的*
for(int i=0;i<=n;i++)
{
for(int j=1;j<=cnt;j++)
{
if(str[i]=='*'&&str[i+j]=='*'&&str[i+2*j]=='*'&&str[i+3*j]=='*'&&str[i+4*j]=='*')//判断5个*距离是否相同一直遍历到cnt
{
flag=true;
break;
}
}
}
if(flag)
puts("yes");
else
puts("no");
}
return 0;
}


END!!!!!!!!!!!!!!!!!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: