Hihocoder1061-Beautiful String
时间限制:10000ms
单点时限:1000ms
内存限制:256MB
描述
We say a string is beautiful if it has the equal amount of 3 or more continuous letters (in increasing order.)
Here are some example of valid beautiful strings: “abc”, “cde”, “aabbcc”, “aaabbbccc”.
Here are some example of invalid beautiful strings: “abd”, “cba”, “aabbc”, “zab”.
Given a string of alphabets containing only lowercase alphabets (a-z), output “YES” if the string contains a beautiful sub-string, otherwise output “NO”.
输入
The first line contains an integer number between 1 and 10, indicating how many test cases are followed.
For each test case: First line is the number of letters in the string; Second line is the string. String length is less than 10MB.
输出
For each test case, output a single line “YES”/“NO” to tell if the string contains a beautiful sub-string.
提示
Huge input. Slow IO method such as Scanner in Java may get TLE.
样例输入
4 3 abc 4 aaab 6 abccde 3 abb
样例输出
YES NO YES NO
题意
如果给出的字符串有连续递增的三个字母或者有等量连续递增的三个字母,则输出YES,结合样例理解。
思路
我们只需要判断到3个就行了,用一个cnt数组记录对应字母的个数,把中间那个拿出来比较,只要又一个不同就将上一个扫描过的字母放到第一个不同的字母那里方便比较,就是中间的小于等于两边且是属于且中间的字母也小于等于前后的的就符合条件
代码
#include<bits/stdc++.h>
using namespace std;
#define maxn 10000000
int cnt[maxn];
int main() {
int t;
cin >> t;
while(t--) {
int n;
cin >> n;
string s;
cin >> s;
int flag = ;
int cur = ;
cnt[cur] = ;
for(int i = ; i < n; i++) {
if(s[i] == s[i - ])
cnt[cur]++;//字母相同时cur没变,相当于去重
else {
s[++cur] = s[i];//
cnt[cur] = ;
}
}
for(int i = ; i < cur; i++) {
if(s[i] == s[i - ] + && s[i] + == s[i + ] && cnt[i] <= cnt[i - ] && cnt[i] <= cnt[i + ]) {
flag = ;
break;
}
}
puts(flag ? "YES" : "NO");
}
return ;
}
Hihocoder1061-Beautiful String的更多相关文章
- Codeforces Round #604 (Div. 2) A. Beautiful String
链接: https://codeforces.com/contest/1265/problem/A 题意: A string is called beautiful if no two consecu ...
- hiho一下:Beautiful String
hiho一下:Beautiful String 记不清这是 hiho一下第几周的题目了,题目不难,不过对于练习编程,训练思维很有帮助.况且当时笔者处于学习算法的早期, 所以也希望刚接触算法的同学能多去 ...
- CF1328B K-th Beautiful String
CF1328B K-th Beautiful String,然而CF今天却上不去了,这是洛谷的链接 题意 一个长度为\(n\)的字符串,有2个\(\texttt{b}\)和\(n-2\)个\(\tex ...
- hihocoder 1061.Beautiful String
题目链接:http://hihocoder.com/problemset/problem/1061 题目意思:给出一个不超过10MB长度的字符串,判断是否里面含有一个beautiful strings ...
- Codeforces Round #604 (Div. 2) A. Beautiful String(贪心)
题目链接:https://codeforces.com/contest/1265/problem/A 题意 给出一个由 a, b, c, ? 组成的字符串,将 ? 替换为 a, b, c 中的一个字母 ...
- HackerRank beautiful string
问题 https://vjudge.net/problem/HackerRank-beautiful-string 给一个字符串S,可以任意取走S中的两个字符从而得到另外一个字符串P,求有多少种不同的 ...
- B. Pasha and String
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- UESTC_Ferris Wheel String 2015 UESTC Training for Search Algorithm & String<Problem L>
L - Ferris Wheel String Time Limit: 3000/1000MS (Java/Others) Memory Limit: 43000/43000KB (Java/ ...
- Pasha and String(思维,技巧)
Pasha and String Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u S ...
- Nikita and string [思维-暴力] ACM
codeforces Nikita and string time limit per test 2 seconds memory limit per test 256 megabytes O ...
随机推荐
- Git 常用命令速查(转载)
git branch 查看本地所有分支git status 查看当前状态 git commit 提交 git branch -a 查看所有的分支git branch -r 查看远程所有分支git co ...
- C#学习 第九节
构造器 1.构造器(constructor)是类型的成员之一: 2.狭义的构造器是指“实例构造器”(instance constructor): 3.构造器的调用 student stu =new s ...
- [USACO12MAR]摩天大楼里的奶牛Cows in a Skyscraper (状态压缩DP)
不打算把题目放着,给个空间传送门,读者们自己去看,传送门(点我) . 这题是自己做的第一道状态压缩的动态规划. 思路: 在这题中,我们设f[i]为i在二进制下表示的那些牛所用的最小电梯数. 设g ...
- 【hihocoder 1317】搜索四·跳舞链
[题目链接]:http://hihocoder.com/problemset/problem/1317 [题意] [题解] dfs就能过吧. 在选取的时候; 把选取的这一行,占据的列,列的权值+1; ...
- Jenkins学习总结(6)——了解DevOps的前世今生
DevOps是什么?从哪里来? DevOps的概念 DevOps一词的来自于Development和Operations的组合,突出重视软件开发人员和运维人员的沟通合作,通过自动化流程来使得软件构建. ...
- ASP.NET--identity笔记及截图
aspnetUsers aspnetRoles aspnetUserroles aspnetUserClaims 存储用户user额外信息的键值对 aspnetUserLogins 第三方登陆的控件 ...
- Android自己定义对话框实现QQ退出界面
效果 首先看下qq的效果图,点击菜单button后点退出就会出现如图的对话框. 从上图能够看出,该对话框有一个圆角,以及标题,提示信息,两个button,button颜色是白色,button点击后背景 ...
- HDU4763-Theme Section(KMP+二分)
Theme Section Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- ym—— Android网络框架Volley(终极篇)
转载请注明本文出自Cym的博客(http://blog.csdn.net/cym492224103).谢谢支持! 没看使用过Volley的同学能够,先看看Android网络框架Volley(体验篇)和 ...
- html与JacaScript中的重要思想:预留后路、向后兼容、js分离
以一个简单的web程序为例 详细设计模式请配合代码及凝视食用 <!DOCTYPE html> <!-- 1 预留退路:假设用户禁用了js.链接还能正常显示吗?(href) 2 分离j ...