标签:first down padding cnn log vhd 比较 rvm 限制
时间限制: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 = 0; int cur = 0; cnt[cur] = 1; for(int i = 1; i < n; i++) { if(s[i] == s[i - 1]) cnt[cur]++; else { s[++cur] = s[i]; cnt[cur] = 1; } } for(int i = 1; i < cur; i++) { if(s[i] == s[i - 1] + 1 && s[i] + 1 == s[i + 1] && cnt[i] <= cnt[i - 1] && cnt[i] <= cnt[i + 1]) { flag = 1; break; } } puts(flag ? "YES" : "NO"); } return 0; }
Hihocoder1061-Beautiful String
标签:first down padding cnn log vhd 比较 rvm 限制
原文地址:http://www.cnblogs.com/zhien-aa/p/6279520.html