Codeforces Round #256 (Div. 2/B)/Codeforces448B_Suffix Structures(字符串处理)
automaton 去掉随意字符后成功转换
array 改变随意两字符后成功转换
再者是两个都有和两个都没有
#include <iostream>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <algorithm>
#include <cmath>
using namespace std; int main()
{
char str1[110],str2[110];
int h1[100],h2[100],i,j;
while(cin>>str1>>str2)
{
memset(h1,0,sizeof(h1));
j=0;
int l1=strlen(str1),l2=strlen(str2);
for(i=0; i<l2,j<l1;)
{
if(str2[i]==str1[j])
{
j++;
i++;
}
else j++;
}
if(i==l2)
cout<<"automaton"<<endl;
else
{
for(i=0; i<l1; i++)
{
h1[str1[i]-'a']++;
}
for(i=0; i<l2; i++)
{
if(h1[str2[i]-'a'])
h1[str2[i]-'a']--;
else break;
}
if(i==l2&&l1==l2)
{
cout<<"array"<<endl;
}
else if(i==l2&&l1!=l2)
cout<<"both"<<endl;
else cout<<"need tree"<<endl; }
}
}
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".
Codeforces Round #256 (Div. 2/B)/Codeforces448B_Suffix Structures(字符串处理)的更多相关文章
- Codeforces Round #256 (Div. 2) B. Suffix Structures(模拟)
题目链接:http://codeforces.com/contest/448/problem/B --------------------------------------------------- ...
- 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 (448B) Suffix Structures
题意就是将第一个字符串转化为第二个字符串,支持两个操作.一个是删除,一个是更换字符位置. 简单的字符串操作!. AC代码例如以下: #include<iostream> #include& ...
- 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) D. Multiplication Table(二进制搜索)
转载请注明出处:viewmode=contents" target="_blank">http://blog.csdn.net/u012860063?viewmod ...
- 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) 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 ...
- Codeforces Round #256 (Div. 2) D. Multiplication Table
主题链接:http://codeforces.com/contest/448/problem/D 思路:用二分法 code: #include<cstdio> #include<cm ...
随机推荐
- 排序算法之奇偶排序 JAVA奇偶排序算法
奇偶排序法的思路是在数组中重复两趟扫描.第一趟扫描选择所有的数据项对,a[j]和a[j+1],j是奇数(j=1, 3, 5……).如果它们的关键字的值次序颠倒,就交换它们.第二趟扫描对所有的偶数数据项 ...
- AppDomain.CurrentDomain.GetAssemblies()
AppDomain.CurrentDomain.GetAssemblies() ,获取已加载到此应用程序域的执行上下文中的程序集 解释地址 从微软的解释也可以得知,这个方法只能获取已经加载到此应用程序 ...
- SQL Server 和CLR集成
通过在 Microsoft SQL Server 中托管 CLR(称为 CLR 集成),可以在托管代码中编写存储过程.触发器.用户定义函数.用户定义类型和用户定义聚合函数. 因为托管代码在执行之前会编 ...
- MSSQL 查询统计某状态出现的次数及累计时间
1.问题来源 最近客户需要统计某个设备,某状态,在某一个时间段内出现的次数,并计算累计出现的时间. 数据源如下: 现在如果要统计UPSCTSTA状态为D出现的次数(同一状态,连续出现的认为是一次),并 ...
- HashMap工作原理
hashmap存储的为key-value键值对,get的时间复杂度是O(1),具体实现原理如下: 1. hashmap是基于数组之上,通过一定算法,用空间转换时间 2. hashmap的数据结构为数组 ...
- Linux程序设计笔记
使用size命令查看二进制文件时,结果并不一定和预测占用内存大小一致,因为可能存在内存对齐,导致内存字节数比实际的更多 在C语言中,字符串常量存放在text segment中,在C++中却是存储在da ...
- jquery中的replaceWith()和html()有什么区别?
区别在于,html()会替换指定元素内部的HTML,而replaceWith()会替换元素本身及其内部的HTML. 例子: 1 <div id="myid" /> 1 ...
- KACK的处理方法
demo: .eq { color:#f00;/*标准浏览器*/ color:#f30\0;/*IE8,IE9,opera*/ *color:#c00;/*IE7及IE6*/ _color:#600; ...
- Swift —构造函数与存储属性初始化-备
构造函数的主要作用是初始化实例,其中包括:初始化存储属性和其它的初始化.在Rectangle类或结构体中,如果在构造函数中初始化存储属性width和height后,那么在定义他们时就不需要初始化了. ...
- ubuntu14.04 reaver不能正常使用
原帖地址: ubuntu14.04 reaver不能正常使用 http://forum.anywlan.com/thread-282404-1-1.html (出处: http://www.anywl ...