Codeforces Round #256 (Div. 2) B Suffix Structures
Description
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.
Input
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.
Output
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.
Sample Input
- automaton
tomat
- automaton
- array
arary
- array
- both
hot
- both
- need
tree
- need tree
Hint
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 <cstring>
- using namespace std;
- int main()
- {
- char s[],t[];
- int as[],at[],flag;
- while(cin>>s>>t)
- {
- flag=;
- memset(as,,sizeof(as));
- memset(at,,sizeof(at));
- int lens,lent;
- lens=strlen(s);
- lent=strlen(t);
- for(int i=;i<lens;i++)
- as[s[i]-'a']++;
- for(int i=;i<lent;i++)
- at[t[i]-'a']++;
- for(int i=;i<;i++)
- if(as[i]>=at[i])
- continue;
- else {flag=; break; }
- if(flag==)
- {
- if(lens==lent)
- cout<<"array"<<endl;
- else
- {
- int r=;
- for(int i=,j=;i<lens;i++)
- {
- if(s[i]==t[j])
- j++;
- if(j==lent)
- {
- r=;break;
- }
- }
- if(r) cout<<"automaton"<<endl;
- else cout<<"both"<<endl;
- }
- }
- else
- {
- cout<<"need tree"<<endl;
- }
- }
- return ;
- }
- #include <iostream>
- #include <cstring>
- using namespace std;
- int main()
- {
- char s[],t[];
- int as[],at[],flag;
- while(cin>>s>>t)
- {
- flag=;
- memset(as,,sizeof(as));
- memset(at,,sizeof(at));
- int lens,lent;
- lens=strlen(s);
- lent=strlen(t);
- for(int i=;i<lens;i++)
- as[s[i]-'a']++;
- for(int i=;i<lent;i++)
- at[t[i]-'a']++;
- for(int i=;i<;i++)
- if(as[i]>=at[i])
- continue;
- else {flag=; break; }
- if(flag==)
- {
- if(lens==lent)
- cout<<"array"<<endl;
- else
- {
- int r=;
- for(int i=,j=;i<lens;i++)
- {
- if(s[i]==t[j])
- j++;
- if(j==lent)
- {
- r=;break;
- }
- }
- if(r) cout<<"automaton"<<endl;
- else cout<<"both"<<endl;
- }
- }
- else
- {
- cout<<"need tree"<<endl;
- }
- }
- return ;
- }
Codeforces Round #256 (Div. 2) B Suffix Structures的更多相关文章
- Codeforces Round #256 (Div. 2) B. Suffix Structures(模拟)
题目链接:http://codeforces.com/contest/448/problem/B --------------------------------------------------- ...
- Codeforces Round #256 (Div. 2/B)/Codeforces448B_Suffix Structures(字符串处理)
解题报告 四种情况相应以下四组数据. 给两字符串,推断第一个字符串是怎么变到第二个字符串. automaton 去掉随意字符后成功转换 array 改变随意两字符后成功转换 再者是两个都有和两个都没有 ...
- Codeforces Round #256 (Div. 2) 题解
Problem A: A. Rewards time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces Round #256 (Div. 2)
A - Rewards 水题,把a累加,然后向上取整(double)a/5,把b累加,然后向上取整(double)b/10,然后判断a+b是不是大于n即可 #include <iostream& ...
- Codeforces Round #256 (Div. 2) B
B. Suffix Structures Bizon the Champion isn't just a bison. He also is a favorite of the "Bizon ...
- Codeforces Round #256 (Div. 2) B (448B) Suffix Structures
题意就是将第一个字符串转化为第二个字符串,支持两个操作.一个是删除,一个是更换字符位置. 简单的字符串操作!. AC代码例如以下: #include<iostream> #include& ...
- Codeforces Round #256 (Div. 2) D. Multiplication Table(二进制搜索)
转载请注明出处:viewmode=contents" target="_blank">http://blog.csdn.net/u012860063?viewmod ...
- Codeforces Round #256 (Div. 2) A. Rewards
A. Rewards time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- Codeforces Round #256 (Div. 2) D. Multiplication Table 二分法
D. Multiplication Table time limit per test 1 second memory limit per test 256 megabytes input st ...
随机推荐
- Web Scraper使用
{ "selectors": [{ "parentSelectors": ["_root"], "type": &quo ...
- VsVim的快捷键使用
.插入命令(可配合数字使用) i 在当前位置前插入 I 在当前行首插入 a 在当前位置后插入 A 在当前行尾插入 o 在当前行之后插入一行 O 在当前行之前插入一行 ni/a/o/I/A/O<E ...
- thinkphp判断是否为手机
一.问题: 近日准备给自己的网站做一个小升级,让用户在手机二维码扫描的时候显示适合手机端来展示的模版[我用的是ThinkPHP3.0],代码是参考别人的 二.实现方法: 这里先说下大概的一个思路 简单 ...
- KMP算法 学习例题 POJ 3461Oulipo
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37971 Accepted: 15286 Description The ...
- Python_Selenium2Library源码分析
I. Introduction Selenium2Library是robot framework中主流的测试网页功能的库, 它的本质是对webdriver的二次封装, 以适应robot框架. 百度上一 ...
- line-height属性详解
line-height属性详解:http://www.cnblogs.com/dolphinX/p/3236686.html
- TCP和UDP报文分片的区别
搞了三年网络,今天才知道这个细节,汗,总结下: MTU大家都知道,是链路层中的网络对数据帧的一个限制,依然以以太网为例,MTU为1500个字节.一个IP数据报在以太网中 传输,如果它的长度大于该MTU ...
- Error js内置错误 js处理错误流程 Throw语句
Exceptional Exception Handling in JavaScript MDN资料 Anything that can go wrong, will go wrong. ...
- php 微信 统一下单 接口实例
<?phpclass wechatAppPay { //接口API URL前缀 const API_URL_PREFIX = 'https://api.mch.weixin.qq.com'; / ...
- gridview XML
GridView动态添加模板列 http://blog.csdn.net/wljhk2006/article/details/24723219 XML与DataTable互转类 http://bl ...