Codeforces Round #256 (Div. 2) B. Suffix Structures(模拟)
题目链接:http://codeforces.com/contest/448/problem/B
----------------------------------------------------------------------------------------------------------------------------------------------------------
欢迎光临天资小屋:http://user.qzone.qq.com/593830943/main
----------------------------------------------------------------------------------------------------------------------------------------------------------
1 second
256 megabytes
standard input
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.
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.
automaton
tomat
automaton
array
arary
array
both
hot
both
need
tree
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 <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;
}
Codeforces Round #256 (Div. 2) B. Suffix Structures(模拟)的更多相关文章
- 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" t ...
- Codeforces Round #256 (Div. 2/B)/Codeforces448B_Suffix Structures(字符串处理)
解题报告 四种情况相应以下四组数据. 给两字符串,推断第一个字符串是怎么变到第二个字符串. automaton 去掉随意字符后成功转换 array 改变随意两字符后成功转换 再者是两个都有和两个都没有 ...
- Codeforces Round #368 (Div. 2) B. Bakery (模拟)
Bakery 题目链接: http://codeforces.com/contest/707/problem/B Description Masha wants to open her own bak ...
- 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 #284 (Div. 2)A B C 模拟 数学
A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #285 (Div. 2) A B C 模拟 stl 拓扑排序
A. Contest time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- Codeforces Round #256 (Div. 2) B (448B) Suffix Structures
题意就是将第一个字符串转化为第二个字符串,支持两个操作.一个是删除,一个是更换字符位置. 简单的字符串操作!. AC代码例如以下: #include<iostream> #include& ...
随机推荐
- 《你又怎么了我错了行了吧团队》第七次作业:团队项目完善&编码
<你又怎么了我错了行了吧团队>第七次作业:团队项目完善&编码 项目 内容 这个作业属于哪个课程 软件工程 这个作业的要求在哪里 实验十一 团队名称 你又怎么了我错了行了吧 作业学习 ...
- JavaScript和CSS实用工具、库与资源
JavaScript和CSS实用工具.库与资源 JavaScript 库 Particles.js - 一个用于在网页上创建漂亮的浮动粒子的 JS 库: Three.js - 用于在网页上创建 3 ...
- SpringBoot2.0 监听器ApplicationListener的使用-监听ApplicationReadyEvent事件
参考:http://www.shareniu.com/article/73.htm 一.需求是想将我的写一个方法能在项目启动后就运行,之前使用了redis的消息监听器,感觉可以照着监听器这个思路做,于 ...
- [poj 2185] Milking Grid 解题报告(KMP+最小循环节)
题目链接:http://poj.org/problem?id=2185 题目: Description Every morning when they are milked, the Farmer J ...
- Java 8 Concurrency Tutorial--转
Threads and Executors Welcome to the first part of my Java 8 Concurrency tutorial. This guide teache ...
- APACHE KYLIN™ 概览(分布式分析引擎)
Apache Kylin™是一个开源的分布式分析引擎,提供Hadoop/Spark之上的SQL查询接口及多维分析(OLAP)能力以支持超大规模数据,最初由eBay Inc. 开发并贡献至开源社区.它能 ...
- 洛谷P1067 多项式输出(模拟)
题目描述 一元 n 次多项式可用如下的表达式表示: 其中,aixi称为 i 次项,ai 称为 i 次项的系数.给出一个一元多项式各项的次数和系数,请按照如下规定的格式要求输出该多项式: 1. 多项式中 ...
- Mojo C++ Bindings API
This document is a subset of the Mojo documentation. Contents Overview Getting Started Interfaces Ba ...
- 【模板】扩展中国剩余定理(EXCRT)
扩展中国剩余定理,是求解形如:$x\equiv a_{1}($ mod $b_{1})$$x\equiv a_{2}($ mod $b_{2})$$x\equiv a_{3}($ mod $b_{3} ...
- 洛谷P3567 [POI2014]KUR-Couriers 主席树
挺裸的,没啥可讲的. 不带修改的主席树裸题 Code: #include<cstdio> #include<algorithm> using namespace std; co ...
