欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

hihocoder 1061.Beautiful String

发布时间:2025/6/17 编程问答 67 豆豆
生活随笔 收集整理的这篇文章主要介绍了 hihocoder 1061.Beautiful String 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

题目链接:http://hihocoder.com/problemset/problem/1061

题目意思:给出一个不超过10MB长度的字符串,判断是否里面含有一个beautiful strings的子串:连续递增且数量相等的字母。

  照着题目分析翻译的代码。。。

  分析得很到位呢,大赞 ^_^

  http://hihocoder.com/discuss/question/2083

  hiho的题目其实挺好的,有专题,有分析,有代码 & 思路参考。。。

  想想出来工作那么久,浮躁的心啊,一个多快两个月没碰啦,得捡回来呢~~~继续ACM哇,为T-shirt fighting !

  

1 #include <iostream> 2 #include <cstdio> 3 #include <cstdlib> 4 #include <cstring> 5 using namespace std; 6 7 const int maxn = 1024*1024*10; // 10MB的字节(1024字节=1KB,1024K=1M) 8 char str[maxn], s[maxn]; 9 int cnt[maxn]; 10 11 int main() 12 { 13 #ifndef ONLINE_JUDGE 14 freopen("in.txt", "r", stdin); 15 #endif // ONLINE_JUDGE 16 17 int n, cas; 18 while (scanf("%d", &cas) != EOF) { 19 while (cas--) { 20 scanf("%d", &n); 21 scanf("%s", str); 22 memset(cnt, 0, sizeof(cnt)); 23 int num = 0; 24 int c = 1; 25 for (int i = 0; i < n; i++) { 26 if (str[i] == str[i+1]) { 27 c++; 28 } 29 else { 30 s[num] = str[i]; 31 cnt[num++] = c; 32 c = 1; 33 } 34 } 35 36 bool flag = false; 37 for (int i = 1; i < num; i++) { 38 if (s[i-1]+1 == s[i] && s[i]+1 == s[i+1] && cnt[i-1] >= cnt[i] && cnt[i] <= cnt[i+1]) { 39 flag = true; 40 break; 41 } 42 } 43 printf("%s\n", flag ? "YES" : "NO"); 44 } 45 } 46 return 0; 47 }

 

  

转载于:https://www.cnblogs.com/windysai/p/5043942.html

总结

以上是生活随笔为你收集整理的hihocoder 1061.Beautiful String的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。