Time limit: 10000ms
Single point time limit: 1000ms
Memory Limit: 256MB
Describe
We say a string is beautiful if it have the equal amount of 3 or more continuous letters (in increasing order.)
Here is some example of valid beautiful strings: "abc", "CDE", "AABBCC", "AAABBBCCC".
Here is 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".
Input
The first line contains an integer number between 1 and ten, indicating how many test cases is followed.
For each test Case:first the number of letters in the string; Second is the string. String length is less than 10MB.
Output
For each test case, output A, "YES" or "NO" to-tell if the string contains a beautiful sub-string.
Tips
Huge input. Slow IO method such as Scanner in Java may get TLE.
Sample input
4 3 ABC 4 AAAB 6 ABCCDE 3 ABB
Sample output
Yes No Yes No
Test instructions
If the given string has a continuous increment of three letters or a constant increment of three letters, then the output is yes, in conjunction with the sample understanding.
Ideas
We only need to determine the 3, with a CNT array to record the number of corresponding letters, the middle of the comparison, that is, the middle of less than equal to the two sides and is the middle of the letter is less than or equal to the same conditions
Code
#include <bits/stdc++.h>using namespacestd;#defineMAXN 10000000intCNT[MAXN];intMain () {intT; CIN>>T; while(t--) { intN; CIN>>N; strings; CIN>>s; intFlag =0; intCur =0; Cnt[cur]=1; for(inti =1; I < n; i++) { if(S[i] = = S[i-1]) Cnt[cur]++; Else{s[++cur] =S[i]; Cnt[cur]=1; } } for(inti =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