Suffix Structures(字符串的“翻译”)

来源:互联网 发布:nat穿越 软件 编辑:程序博客网 时间:2024/06/03 00:37

题目来源:[NWPU][2014][TRM][4]无题  C题

http://vjudge.net/contest/view.action?cid=50333#problem/C

作者:npufz

题目:

描述:

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 t even 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.

代码:

#include <iostream>#include <cstring>#include <cstdio>using namespace std;int main(){    char s1[1000],s2[1000],t;    int num1,num2,sum1[27],sum2[27];    bool flag1=false,flag2=false;    int i,j,k,j3;    //cin>>k;   // while(k--){  scanf(" %s%s",s1,s2);    //puts(s1);    //puts(s2);  num1=0;    while(s1[num1++]);num1--;   //cout<<num1<<endl;    num2=0;    while(s2[num2++]);num2--;    //cout<<num2<<endl;    if(num1>=num2)    {j3=0;    for(i=0;i<num1&&s2[j3];i++)    if(s1[i]==s2[j3]) j3++;    if(s2[j3]=='\0')  flag1=true;   for(i=0;i<27;i++) {sum1[i]=0;sum2[i]=0;}   for(i=0;i<num1;i++)  sum1[s1[i]-'a']++;   for(i=0;i<num2;i++)  sum2[s2[i]-'a']++;   flag2=true;   for(i=0;i<26;i++)   if(sum2[i]>sum1[i])  {flag2=false; break;}   }    if(flag1&&num2==num1)  printf("array\n");    else if(flag1&&num2<num1) printf("automaton\n");   else if(flag2&&num2<num1)      printf("both\n");   else if(flag2&&num2==num1)     printf("array\n");   else printf("need tree\n");   //}return 0;}

反思:一开始理解错题目的意思了,就错了,正确理解题意是十分重要


0 0
原创粉丝点击