ZeptoLab Code Rush 2015 A. King of Thieves
2015-04-05 11:58
330 查看
1.题目描述:点击打开链接
2.解题思路:本题要求在一个串中找出5个等距离的‘*’,如果有,输出yes,否则输出no。思路很清晰,首先枚举步长len,然后枚举起点i,判断是否能够连续不间断地跳跃5次且均为‘*’即可。本题还可以加速寻找,先寻找是否存在‘*****’,如果有,直接输出yes。
3.代码:
2.解题思路:本题要求在一个串中找出5个等距离的‘*’,如果有,输出yes,否则输出no。思路很清晰,首先枚举步长len,然后枚举起点i,判断是否能够连续不间断地跳跃5次且均为‘*’即可。本题还可以加速寻找,先寻找是否存在‘*****’,如果有,直接输出yes。
3.代码:
#define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<algorithm> #include<string> #include<sstream> #include<set> #include<vector> #include<stack> #include<map> #include<queue> #include<deque> #include<cstdlib> #include<cstdio> #include<cstring> #include<cmath> #include<ctime> #include<functional> using namespace std; string s; int main() { //freopen("t.txt", "r", stdin); int n; while (~scanf("%d", &n)) { cin >> s; int i; for (i = 0; i < n; i++) if (s[i] == '*')//找到第一个‘*’的位置 break; int cnt, ok = 0; if (strstr(s.c_str(), "*****") != NULL)ok = 1;//加速措施 else { for (int len = 1; len < n; len++)//枚举步长 { int cnt, k; for (int j = i; j < n - 4 * len; j++)//枚举起点 { cnt = 0, k = 0; while (k < 5) { if (s[j + k*len] == '*')cnt++; else break; k++; } if (cnt == 5){ ok = 1; break; } } } } if (ok)puts("yes"); else puts("no"); } return 0; }
相关文章推荐
- ZeptoLab Code Rush 2015 A. King of Thieves 暴力
- Codeforces ZeptoLab Code Rush 2015 A. King of Thieves
- ZeptoLab Code Rush 2015 A. King of Thieves
- ZeptoLab Code Rush 2015 B. Om Nom and Dark Park
- CodeForces ZeptoLab Code Rush 2015
- ZeptoLab Code Rush 2015 C. Om Nom and Candies
- ZeptoLab Code Rush 2015
- C. Om Nom and Candies(ZeptoLab Code Rush 2015)
- ZeptoLab Code Rush 2015 B. Om Nom and Dark Park
- ZeptoLab Code Rush 2015 B. Om Nom and Dark Park DFS
- ZeptoLab Code Rush 2015---C. Om Nom and Candies
- ZeptoLab Code Rush 2015 C. Om Nom and Candies 暴力
- 【codeforces】 ZeptoLab Code Rush 2015 A,B,C,D,E题解
- CodeForces--ZeptoLab Code Rush 2015 (我参加的第一场cf比赛)
- ZeptoLab Code Rush 2015 C题Om Nom and Candies
- ZeptoLab Code Rush 2015
- zjnu ZeptoLab Code Rush 2015 replay
- ZeptoLab Code Rush 2015_B - Om Nom and Dark Park
- ZeptoLab Code Rush 2015(树)
- Codeforces ZeptoLab Code Rush 2015 B. Om Nom and Dark Park DFS