Codeforces Round #256 (Div. 2) B. Suffix Structures(模拟)

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

----------------------------------------------------------------------------------------------------------------------------------------------------------
欢迎光临天资小屋http://user.qzone.qq.com/593830943/main

----------------------------------------------------------------------------------------------------------------------------------------------------------

B. Suffix Structures

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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

Sample test(s)

input

automaton
tomat

output

automaton

input

array
arary

output

array

input

both
hot

output

both

input

need
tree

output

need tree

Note

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 <algorithm>
using namespace std;
#define N 47
#define M 100000
#include <cstring>
int a[N],b[N];
char s[M+17], t[M+17];
void init()
{
	memset(a,0,sizeof(a));
	memset(b,0,sizeof(b));
}
int main()
{
	int i, j;
	while(cin >> s)
	{
		init();
		cin>>t;
		int lens = strlen(s);
		int lent = strlen(t);
		for(i = 0; i < lens; i++)
		{
			a[s[i]-'a']++;
		}
		for(i = 0; i < lent; i++)
		{
			b[t[i]-'a']++;
		}
		int flag = 0;
		if(lens < lent)
		{
			flag = 1;
		}
		for(i = 0; i < 26; i++)
		{
			if(a[i] < b[i])
			{
				flag = 1;
				break;
			}
		}
		if(flag == 1)
		{
			cout<<"need tree"<<endl;
			continue;
		}
		if(lens == lent)
		{
			cout<<"array"<<endl;
			continue;
		}
		int p = 0, j = 0;
		for(i = 0; i < lent; i++)
		{
			while(t[i]!=s[j] && j < lens)
			{
				j++;
			}
			if(j >= lens) //表示不存在不交换s子串的顺序能组成t的情况
			{
				p = 1;
				break;
			}
			j++;
		}
		if(p == 1)
		{
			cout<<"both"<<endl;
			continue;
		}
		cout<<"automaton"<<endl;
	}
	return 0;
}
时间: 2024-11-05 20:25:43

Codeforces Round #256 (Div. 2) B. Suffix Structures(模拟)的相关文章

Codeforces Round #256 (Div. 2) B. Suffix Structures

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 trans

Codeforces Round #256 (Div. 2/B)/Codeforces448B_Suffix Structures(字符串处理)

解题报告 四种情况相应以下四组数据. 给两字符串,推断第一个字符串是怎么变到第二个字符串. automaton 去掉随意字符后成功转换 array 改变随意两字符后成功转换 再者是两个都有和两个都没有 #include <iostream> #include <cstdio> #include <cstring> #include <stdlib.h> #include <algorithm> #include <cmath> usi

Codeforces Round #256 (Div. 2) B (448B) Suffix Structures

题意就是将第一个字符串转化为第二个字符串,支持两个操作,一个是删除,一个是更换字符位置. 简单的字符串操作!! AC代码如下: #include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #define M 50010 #define inf 100000000 using namespace std; char a[1005],b[1005]; int la,lb; b

Codeforces Round #256 (Div. 2) A/B/C/D

A. Rewards 水题 #include<cstdio> #include<iostream> #include<cstring> using namespace std; int main() { int a1,a2,a3,b1,b2,b3,s,t1,t2,sum1,sum2; while(scanf("%d%d%d",&a1,&a2,&a3)!=EOF) { scanf("%d%d%d",&

Codeforces Round #256 (Div. 2)——Painting Fence

题目连接 题意: n个木条,输入n个木条的高度,每个木条的宽度均为1.现在有长宽均为1的刷子,每次可以选择横着刷或者竖着刷,每次刷的时候不能离开木条,问将所有木条均涂色至少需要刷几次.(刷的时候可以经过已经被刷过的地方) n (1?≤?n?≤?5000),1?≤?ai(高度)?≤?109 分析: 分析一下横着和竖着的关系:假设现在已经有一个操作集合S是答案,那么集合中的操作顺序是可以改变的,即横和竖的顺序可以改变(因为可以经过已经涂色的木条),那么不妨先横着涂色.对于当前[l,r]的区间,答案不

Codeforces Round #256 (Div. 2/C)/Codeforces448C_Painting Fence(分治)

解题报告 给篱笆上色,要求步骤最少,篱笆怎么上色应该懂吧,,,刷子可以在横着和竖着刷,不能跳着刷,,, 如果是竖着刷,应当是篱笆的条数,横着刷的话,就是刷完最短木板的长度,再接着考虑没有刷的木板,,, 递归调用,,, #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define inf 999999999999999 using namespace

Codeforces Round #256 (Div. 2) Multiplication Table

刚刚开始想到一种很暴力但还行的方法,不过在和TK讨论的过程中引出了一个更好的算法 #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> using namespace std; long long n,m,k; long long check(long long x) { long long ans=0; for(int i=1;i<=n;i++) { ans

Codeforces Round #256 (Div. 2)

泛泛解: D:求K大,如果我们二分枚举,如果有O(N)的方法统计,就OK了,先枚举,我们对每一行的统计能够达到O(1),所以很简单了. E:有思路,但是代码能了太弱了,DFS学得太水. 我们发现其实就是一个深度递归结构,只有100000个元素,所以这是一个突破点. 先求出所有因子,然后枚举因子,出现的话深度遍历,结束条件是达到第K层或者因子是1,注意:K大于100000时,要变为100000,因为不可能层数大于100000: C:分治+贪心. 这道真是好题,题解的思路是:对区间(L,R)的点贪心

Codeforces Round #256 (Div. 2)D 二分答案

D. Multiplication Table time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Bizon the Champion isn't just charming, he also is very smart. While some of us were learning the multiplication tabl