Codeforces ZeptoLab Code Rush 2015 A. King of Thieves
来源:互联网 发布:淘宝手机流量互刷软件 编辑:程序博客网 时间:2024/06/08 02:39
题目大意: 给你一个数字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!!!!!!!!!!!!!!!!!
1 0
- Codeforces ZeptoLab Code Rush 2015 A. King of Thieves
- ZeptoLab Code Rush 2015 A. King of Thieves
- Codeforces ZeptoLab Code Rush 2015
- 【codeforces ZeptoLab Code Rush 2015】ABCD题解
- ZeptoLab Code Rush 2015 -- (A,B,C)
- ZeptoLab Code Rush 2015
- 【codeforces】 ZeptoLab Code Rush 2015 A,B,C,D,E题解
- CODEFORCES 526 A. King of Thieves
- CodeForces 526A-King of Thieves
- A. King of Thieves
- A. King of Thieves
- zjnu ZeptoLab Code Rush 2015 replay
- ZeptoLab Code Rush 2015(树)
- 526A - King of Thieves
- CodeForces--ZeptoLab Code Rush 2015 (我参加的第一场cf比赛)
- Codeforces ZeptoLab Code Rush 2015 B. Om Nom and Dark Park DFS
- ZeptoLab Code Rush 2015 B. Om Nom and Dark Park
- ZeptoLab Code Rush 2015 C. Om Nom and Candies
- 支持向量机
- DedeCMS首页调用栏目内容和单页内容的方法
- 使用IntelliJ IDEA开发SpringMVC网站(一)开发环境
- POJ1274 — 二分图匹配模板题
- MFC消息映射机制实现
- Codeforces ZeptoLab Code Rush 2015 A. King of Thieves
- 库2
- spark参数调整
- 几个关键字的理解
- Codeforces Round #363 (Div. 2)D. Fix a Tree
- POJ 1080 Human Gene Functions(字符串匹配得分,dp)
- DedeCMS安全设置 目录执行php脚本限制方法
- Deep learning 译文 -- 第二部分
- [线性DP]尼克的任务