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 ...
随机推荐
- Wcf资料收集
1.简介 http://www.tuicool.com/articles/mqYB32 使用规范 http://blog.51cto.com/zt/219 2.教程系列 http://www.cnbl ...
- Php GMP
GMP是The GNU MP Bignum Library,是一个开源的数学运算库,它可以用于任意精度的数学运算,包括有符号整数.有理数和浮点数.它本身并没有精度限制,只取决于机器的硬件情况. 本函数 ...
- view ondraw
窗口发生重绘时会被应用程序的窗口框架给调用 要使输出的东西始终能在窗口中看到 就可以使用该函数 窗口从到有的时候就会产生WM_PAINT消息,让窗口发生重绘 这是程序就会执行到ONDRAW函数处 所 ...
- JavaScript 禁用键盘按钮
代码写多了,有些使用过的方法和技巧会一时半会想不起来,平日记录下来,方便自己和有需要的人日后查阅. $(document).keydown(function () { if (window.event ...
- JS之对象数组遍历?
一.js实现遍历对象 <script> ","destroy":"97%"}; var props = ""; for ...
- php 数组操作类(整合 给意见)
数组操作函数整理: /* 将一个二维数组按照指定字段的值分组 * * @param array $arr * @param string $keyField * * @return array */ ...
- IOS文件操作的两种方式:NSFileManager操作和流操作
1.常见的NSFileManager文件方法 -(NSData *)contentsAtPath:path //从一个文件读取数据 -(BOOL)createFileAtPath: path cont ...
- 『C # 开发』技能 Get√ ——制作CMD界面的简单GIF图片
今天看到C#课本上个列子把星号(*)有规则打印在控制台中间位置 程序不难,利用的是光标定位函数Console.SetCursorPosition(x, y)做到的 心想是不是弄出一个动态的图案比较好玩 ...
- favicon支持的图片格式
为网站设置favicon有两种方式: 1.网站根目录下放置名为favicon.ico的图片,浏览器就会自动获取: 2.在页面中通过<link rel="shortcut icon&qu ...
- pm2 安装使用
pm2 是全新开发的进程守护服务, 同时集成了负载均衡功能. 以及开机启动, 自动重启有问题进程. 还可以查看各服务进程状态. 使用方法参照:https://github.com/Unitech/pm ...