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 ...
 
随机推荐
- 【转】VGG网络结构及参数
			
VGG网络 VGG16输入224*224*3的图片,经过的卷积核大小为3x3x3,stride=1,padding=1,pooling为采用2x2的max pooling方式: 1.输入224x2 ...
 - bzoj 1191: [HNOI2006]超级英雄Hero 网络流_残量网络
			
题目描述: 现在电视台有一种节目叫做超级英雄,大概的流程就是每位选手到台上回答主持人的几个问题,然后根据回答问题的 多少获得不同数目的奖品或奖金.主持人问题准备了若干道题目,只有当选手正确回答一道题后 ...
 - prevent阻止标签默认行为&stop阻止事件冒泡
			
<form id="vm" v-on:submit.prevent="register"> 1.prevent是preventDefault,阻止标 ...
 - spring rest docs自定义代码片段
			
Spring rest docs 文档插件在生成文档时会默认生成6个代码片段,自适应生成其它片段.通过阅读官方文档发现其可以自定义生成的代码片段,但是官方只说了可以自定义模版,修改现有的代码片段的方法 ...
 - XSS Chanllenges 6-10
			
Stage #6 测试代码</xss> 存在过滤,并且也没有其他输入点,尝试构建" onmousemove="alert(document.domain),并查看源代码 ...
 - php ob缓存
			
用PHP的ob_start();控制您的浏览器cache Output Control 函数可以让你自由控制脚本中数据的输出.它非常地有用,特别是对于:当你想在数据已经输出后,再输出文件头的情况.输出 ...
 - POJ 1061 青蛙的约会( 拓欧经典题 )
			
链接:传送门 思路:简单拓展欧几里德,分析后可以得到方程 x + m * t = y + n * t + L * s( s控制圈数,t代表跳t次会碰面 ),经过化简可以得到 ( n - m ) * t ...
 - spring data JPA使用quartz定时器的具体实现
			
第一步.在pom.xml中的配置 <!--quartz--> <dependency> <groupId>org.quartz-scheduler</grou ...
 - Statement对象sql注入漏洞的问题
			
现在通过mysql以及oracle来测试sql注入 漏洞 mysql中的注释# oracle中的注释为-- 所以注入漏洞就产生了 //登录测试 public void login()throw ...
 - Elasticsearch 7.0 发布都有哪些新特性
			
了解about云知识星球 .pcb{margin-right:0} 问题导读 1.Elasticsearch&Kibana 7.哪些需要修改? 2.Elasticsearch7 有哪些新特性? ...