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 }

  

时间: 2024-10-25 21:19:18

hihocoder 1061.Beautiful String的相关文章

hiho一下 第五十八周 Beautiful String dp

题目1 : 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"

微软校招编程题&quot;Beautiful String&quot;的状态机解法

昨天碰巧看到一道微软校招的编程题,题目大意如下: 如果一个字符串包括三组或者更多组的连续升序字母,每组长度相等,那么我们就称这个字符串是Beautiful String 如下是一些Beautiful String的例子: abc.cde.aabbcc.aaabbbccc 这些不是Beautiful String: abd.cba.aabbc.zab 输入一个只含有小写字母的字符串,如果它含有一个Beautiful的子串,就输出YES,否则输出NO 输入: 第一行是案例个数,之后的每一行是一个数字

Codeforces Round #604 (Div. 2) A. Beautiful String

链接: https://codeforces.com/contest/1265/problem/A 题意: A string is called beautiful if no two consecutive characters are equal. For example, "ababcb", "a" and "abab" are beautiful strings, while "aaaaaa", "abaa&

hiho一下:Beautiful String

hiho一下:Beautiful String 记不清这是 hiho一下第几周的题目了,题目不难,不过对于练习编程,训练思维很有帮助.况且当时笔者处于学习算法的早期, 所以也希望刚接触算法的同学能多去练习一下. 题目介绍 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 We say a string is beautiful if it has the equal amount of 3 or more continuous letters (in increasi

ACM-ICPC国际大学生程序设计竞赛北京赛区(2015)网络练习赛 题目4 : Beautiful String

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 exa

hihoCoder 1596 Beautiful Sequence 搜索

Beautiful Sequence Description 对于一个正整数列a[1], ... , a[n] (n ≥ 3),如果对于所有2 ≤ i ≤ n - 1,都有a[i-1] + a[i+1] ≥ 2 × a[i],则称这个数列是美丽的. 现在有一个正整数列b[1], ..., b[n],请计算:将b数列均匀随机打乱之后,得到的数列是美丽的概率P. 你只需要输出(P × (n!))mod 1000000007即可.(显然P × (n!)一定是个整数) Input 第一行一个整数n. (

Pasha and String(思维,技巧)

Pasha and String Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 525B Description Pasha got a very beautiful string s for his birthday, the string consists of lowercase Latin letters. Th

UESTC_Ferris Wheel String 2015 UESTC Training for Search Algorithm &amp; String&lt;Problem L&gt;

L - Ferris Wheel String Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 43000/43000KB (Java/Others) Submit Status Have you ever been to London? Our Master Qiu will tell you how amazing in London and how funny a Ferris Wheel String is. One day

Codeforces Round #297 (Div. 2)B Pasha and String

B. Pasha and String time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Pasha got a very beautiful string s for his birthday, the string consists of lowercase Latin letters. The letters in the