codeforces 448B. Suffix Structures 解题报告

题目链接:http://codeforces.com/problemset/problem/448/B

题目意思:给出两种操作automaton:可以删除字符串中任意一个字符; array:交换字符串中任意两位。运用这两种操作的次数不限定,问如何运用这两种操作(或其中一种,或两种结合都不能够)使得字符串 s 转换成字符串 t

    昨晚做的时候,顶住疲倦死撑,过不了pretest 5,我以为是因为这组数据:ttauotdf  auto,当时没想到怎么做,太困了......今日做才发现原来要用到两个指针!而且我发现好多AC代码根本过不了这组数据,她们输出的竟然是 automaton!!!幸好作者还是起到模范作用滴^_^

    

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 #include <cstring>
 5 using namespace std;
 6 
 7 const int maxn = 100 + 10;
 8 char s[maxn], t[maxn];
 9 int cnt[maxn];
10 
11 void solve()
12 {
13     int ls = strlen(s);
14     int lt = strlen(t);
15     memset(cnt, 0, sizeof(cnt));
16     for (int i = 0; i < ls; i++)
17         cnt[s[i]-'a']++;
18     for (int i = 0; i < lt; i++)
19         cnt[t[i]-'a']--;
20     int aut, arr, both;
21     aut = arr = both = 1;
22     for (int i = 0, j = 0; i < ls; i++)
23     {
24         if (s[i] == t[j])
25             j++;
26         if (j == lt)
27         {
28             aut ^= 1;
29             break;
30         }
31     }
32     for (int i = 0; i < 26; i++)
33     {
34         arr &= (cnt[i] == 0);   
35         both &= (cnt[i] >= 0);  // 这个“=”很重要,因为有可能s中有的字母t没有!
36     }
37     if (!aut)
38         printf("automaton
");
39     else if (arr)
40         printf("array
");
41     else if (both)
42         printf("both
");
43     else
44         printf("need tree
");
45 }
46 
47 int main()
48 {
49     while (scanf("%s%s", s, t) != EOF)
50     {
51         solve();
52     }
53     return 0;
54 }
原文地址:https://www.cnblogs.com/windysai/p/3853150.html