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!!!!!!!!!!!!!!!!!
相关文章推荐
- poj 1873 The Fortified Forest (位运算枚举 + 凸包周长)
- 支持向量机
- IDR_MAINFRAME中各个字段的含义
- POJ1274 — 二分图匹配模板题
- angularJS测试一 Karma Jasmine Mock
- Delphi 目前使用delay函数功能
- DedeCMS首页调用栏目内容和单页内容的方法
- 【日常练习 01背包】HDU 2602 Bone Collector
- linux on ARM 构建BeagleBone Black系统概述
- php组数玩法
- PHP学习之路之Smarty自定义函数(中)
- GIT的概念
- 1sting(大数递归)
- Delphi Delay 延时计数的功能。 下面的方法都是思路,但是没有用在项目上
- URL列表
- varchar和Nvarchar区别
- QMenuBar
- myPid() 和 myUid() 的区别
- Linux - Runlevel Config
- 织梦DEDECMS首页调用单页文档内容并带过滤HTML的方法