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 ...
随机推荐
- 对服务器磁盘、CPU、内存使用状态,设置163邮件告警
1,桥接模式可上网,首先你的邮箱已经开通yum -y install mailx dos2unix.x86_64 mailx -V[root@localhost ~]# vim /etc/mail. ...
- js提示是否删除
第一种: <a href="javascript:if(confirm('确认删除吗?'))window.location='del.asp'">删除</a> ...
- json与object
json与object的区别:1.JSON是对象,但对象不一定是JSON2.对象的组成是由属性和属性值,也就是KEY->VALUE对组成,value可是是任意的数据类型,当value为一个函数 ...
- String,StringBuffer,StringBuild的区别
1.三者在执行速度方面的比较:StringBuilder > StringBuffer > String 2.String <(StringBuffer,StringBuild ...
- PHP 使用 Kafka 安装拾遗
最近项目开发中需要使用 Kafka 消息队列.经过检索,PHP下面有通用的两种方式来调用 Kafka . php-rdkafka 扩展 以 PHP 扩展的形式进行使用是非常高效的.另外,该项目也提供了 ...
- 关于错误CSC : error CS0006:未能找到元数据文件
在不同的解决方案中把一个项目搬来搬去,终于出现了传说的CSC : error CS0006.编译的时候总是提示一个引用中不存在的项找不到.无论怎样删除项目,删除引用都没法通过生成. 最终解决方案: 用 ...
- 有关elasticsearch分片策略的总结
最近在优化部分业务的搜索吞吐率,结合之前优化过写请求的经验,想和大家讨论下我对es分片在不同场景下的分配策略的思路 原先普通索引我的分片策略是: 主分片=节点数,副本=1,这样可以保证业务数据一定 ...
- PHP 防xss攻击
PHP直接输出html的,可以采用以下的方法进行过滤: 1.htmlspecialchars函数 2.htmlentities函数 3.HTMLPurifier.auto.php插件 4.Remove ...
- 洛谷 P1124 文件压缩
P1124 文件压缩 题目背景 提高文件的压缩率一直是人们追求的目标.近几年有人提出了这样一种算法,它虽然只是单纯地对文件进行重排,本身并不压缩文件,但是经这种算法调整后的文件在大多数情况下都能获得比 ...
- 我的php站点系统分析工具01
出于后的工作需求.须要高速弄清楚整个php站点系统是怎样执行的.抱着试探的心态.写出了这个工具. 临时把它叫做"系统信息动态解析地图"吧,或许"系统信息图"更方 ...