Codeforces Round #256 (Div. 2) —— B
来源:互联网 发布:网络直销怎么做 2017 编辑:程序博客网 时间:2024/06/05 20:11
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".
题意:如果上面的字符串可以通过删除字符来得到下面的字符串,则输出automaton;如果可以通过交换任意字符得到,则输出array;如果需要以上两种方法,则输出both;否则输出need tree;
这题只要多考虑一些情况就行。
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int main(){ int i, j; char a[110], b[110], m1[110], m2[110]; while(~scanf("%s", a)) { scanf("%s", b); int len1 = strlen(a); int len2 = strlen(b); int g = 0; for(i=0; i<len1; i++) if(a[i] == b[g]) g++; if(g == len2) { puts("automaton"); continue; } strcpy(m1,a); strcpy(m2,b); sort(m1, m1+len1); sort(m2, m2+len2); if(strcmp(m1,m2) == 0) { puts("array"); continue; } g = 0; for(i=0; i<len2; i++) { for(j=0; j<len1; j++) { if(b[i] == a[j]) { g++, a[j] = 0; break; } } } if(g == len2) { puts("both"); continue; } puts("need tree"); } return 0;}
- Codeforces Round #256 (Div. 2) —— B
- Codeforces Round #256 (Div. 2) B
- Codeforces Round #256 (Div. 2)(B)
- Codeforces Round #154 (Div. 2)——B
- Codeforces Round #156 (Div. 2)——B
- Codeforces Round #151 (Div. 2)——B
- Codeforces Round #152 (Div. 2)——B
- Codeforces Round #149 (Div. 2)——B
- Codeforces Round #146 (Div. 2)——B
- Codeforces Round #144 (Div. 2)——B
- Codeforces Round #142 (Div. 2)——B
- Codeforces Round #157 (Div. 2)——B
- Codeforces Round #134 (Div. 2)——B
- Codeforces Round #141 (Div. 2)——B
- Codeforces Round #140 (Div. 2)——B
- Codeforces Round #137 (Div. 2)——B
- Codeforces Round #136 (Div. 2)——B
- Codeforces Round #135 (Div. 2)——B
- Android RGB颜色查询对照表
- 移动视频开发中横竖屏转换遇到的BUG(Android)
- 搞定 jquery jsonp
- uva_253 - Cube painting
- void与void*
- Codeforces Round #256 (Div. 2) —— B
- Java调用XML的方法:DocumentBuilderFactory
- 【BZOJ】【P3678】【wangxz与OJ】【题解】【rope】
- HDU 4944
- Struts2中过滤器和拦截器的区别
- 获取当前显示设备数量
- 墨菲定律、二八法则、马太效应、手表定理、“不值得”定律、彼得原理、零和游戏、华盛顿合作规律、酒与污水定律、水桶定律、蘑菇管理原理、钱的问题、奥卡姆剃刀等13条是左右人生的金科玉律 .
- C# --习题笔记02
- Nginx从入门到精通阅读笔记2