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 ... 
随机推荐
- The socket  is   closed!
			关闭mongodb /usr/local/app/mongidb//bin/mongod --shutdown --dbpath /usr/local/data/mongo/data/ 然 ... 
- Linux系统下的  /etc/fstab 文件解读
			1 [root@localhost ~]# cat /etc/fstab 2 3 # 4 # /etc/fstab 5 # Created by anaconda on Sat Nov 3 12:03 ... 
- 《黑白团团队》第八次团队作业:Alpha冲刺 第二天
			项目 内容 作业课程地址 任课教师首页链接 作业要求 团队项目 填写团队名称 黑白团团队 填写具体目标 认真负责,完成项目 团队项目Github仓库地址链接. 第二天 日期:2019/6/16 成员 ... 
- 使用maven服务器插件  运行项目
			使用jetty插件 部署运行 创建一个maven项目:去Maven仓库中寻找jetty插件 然后复制到pom.xml中 使用命令 运行程序: 然后控制台打印: 通过浏览器 访问: ----- ... 
- ZOJ 3891 K-hash
			K-hash Time Limit: 2000ms Memory Limit: 131072KB This problem will be judged on ZJU. Original ID: 38 ... 
- C#-WinForm中文本框的中文乱码问题
			上面这句话可以解决textbox中的中文乱码问题 来自为知笔记(Wiz) 附件列表 QQ图片20151218124007.png 
- 使用angularjs的$http.post异步提交数据时,服务器接收不了的问题
			一,在正常情况下,使用表单的post方法提交数据,默认请求头的Content-Type:application/x-www-form-urlencoded类型, 提交数据格式如下: 二,使用angul ... 
- six.moves的用法
			six是用来兼容python 2 和 3的,我猜名字就是用的2和3的最小公倍数. six.moves 是用来处理那些在2 和 3里面函数的位置有变化的,直接用six.moves就可以屏蔽掉这些变化 P ... 
- BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第11章节--为Office和SP解决方式开发集成Apps  集成SP和Office App
			BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第11章节--为Office和SP解决方式开发集成Apps 集成SP和Office App 你能够用两种 ... 
- html5的postmessage实现js前端跨域訪问及调用解决方式
			关于跨域訪问.使用JSONP的方法.我前面已经demo过了.详细见http://supercharles888.blog.51cto.com/609344/856886,HTML5提供了一个很强大的A ... 
