cf448B. Suffix Structures
来源:互联网 发布:简明python基础教程 编辑:程序博客网 时间:2024/05/17 06:09
Bizon the Champion isn't just a bison. He also is a favorite of the "Bizons" team.
At a competition the "Bizons" got the following problem: "You are given two distinct words (strings of English letters), s and t. You need to transform word s into word t". The task looked simple to the guys because they know the suffix data structures well. Bizon Senior loves suffix automaton. By applying it once to a string, he can remove from this string any single character. Bizon Middle knows suffix array well. By applying it once to a string, he can swap any two characters of this string. The guys do not know anything about the suffix tree, but it can help them do much more.
Bizon the Champion wonders whether the "Bizons" can solve the problem. Perhaps, the solution do not require both data structures. Find out whether the guys can solve the problem and if they can, how do they do it? Can they solve it either only with use of suffix automaton or only with use of suffix array or they need both structures? Note that any structure may be used an unlimited number of times, the structures may be used in any order.
The first line contains a non-empty word s. The second line contains a non-empty word t. Words s and t are different. Each word consists only of lowercase English letters. Each word contains at most 100 letters.
In the single line print the answer to the problem. Print "need tree" (without the quotes) if word s cannot be transformed into word teven with use of both suffix array and suffix automaton. Print "automaton" (without the quotes) if you need only the suffix automaton to solve the problem. Print "array" (without the quotes) if you need only the suffix array to solve the problem. Print "both" (without the quotes), if you need both data structures to solve the problem.
It's guaranteed that if you can solve the problem only with use of suffix array, then it is impossible to solve it only with use of suffix automaton. This is also true for suffix automaton.
automatontomat
automaton
arrayarary
array
bothhot
both
needtree
need tree
In the third sample you can act like that: first transform "both" into "oth" by removing the first character using the suffix automaton and then make two swaps of the string using the suffix array and get "hot".
#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#include<cmath>#include<queue>#include<list>#include<vector>using namespace std;const int maxn=10010;int vis1[30],vis2[maxn];char str1[110];char str2[110];int main(){int n,i,j,k;scanf("%s",str1);scanf("%s",str2);int ans=0,len1=strlen(str1),len2=strlen(str2);int num=0;for(i=0;i<len1;++i){if(str1[i]==str2[num])num++;}if(num>=len2){printf("automaton\n");}else {bool sign=true,sign2=true;for(i=0;i<len1;++i){vis1[str1[i]-'a']++;}for(i=0;i<len2;++i){vis2[str2[i]-'a']++;}for(i=0;i<26;++i){if(vis1[i]!=vis2[i]){sign2=false;}if(vis1[i]<vis2[i])sign=false;}if(sign2){printf("array\n");}else if(sign){printf("both\n");}else {printf("need tree\n");}}return 0;}
- cf448B Suffix Structures
- cf448B. Suffix Structures
- Data Structures, Suffix Trees
- B. Suffix Structures
- codeforces B. Suffix Structures
- B. Suffix Structures
- Codeforces Suffix Structures
- Codeforces 448B. Suffix Structures
- B - Suffix Structures(CF,255)
- Codeforces 448B Suffix Structures
- Suffix Structures(字符串的“翻译”)
- CodeForces 448-B. Suffix Structures
- CodeForces 448B Suffix Structures
- codeforces 448 B. Suffix Structures
- codeforces Div.2 B.Suffix Structures
- Codeforces Div. 2 #256-B. Suffix Structures
- Suffix Structures - #256 (Div. 2) B (448B) 陷阱题
- Codeforces Round #256 (Div. 2) B. Suffix Structures
- JavaScript学习总结(十四)——JavaScript编写类的扩展方法
- 【fastweixin框架教程3】JAVA进行HTTPS网站访问,PKIX path building failed解决方法
- 翻译mos文章rac脑裂导致节点的驱逐
- 超简单socket客户端例子
- JavaScript学习总结(十五)——Function类
- cf448B. Suffix Structures
- Cassandra 2.x中文教程(20):主配置文件cassandra.yaml介绍(上) 2
- OPENGL es版本和OGL 及android关系
- JavaScript学习总结(十六)——Javascript闭包(Closure)
- SVN命令大全
- Vi编辑器的基本使用
- C++实验5-项目2数组选择
- 专访许雪松:深入理解嵌入式开发
- web前端标准化代码