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

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;

        }
    }
}

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


版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/118800.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 指针初始化

    指针初始化引用:https://blog.csdn.net/qq_43574794/article/details/84864349https://baike.baidu.com/item/%E6%8C%8

    2022年7月3日
    25
  • docker 创建容器,端口映射(docker exec 进入容器)

    今天用docker的swarm搭建了一个集群,在启动主节点的swarm的时候出错了,报的错误是:/usr/bin/docker-current:Errorresponsefromdaemon:driverfailedprogrammingexternalconnectivityonendpointgoofy_bose(317173685c23c029fd5f28b88

    2022年4月16日
    77
  • 通过 MATLAB 处理大数据[通俗易懂]

    通过 MATLAB 处理大数据[通俗易懂]原文链接:通过MATLAB处理大数据大数据指的是创建的数据和供分析的数据的数量与速率迅速增加。大数据使分析师和数据专家有机会获得更好的见解,进行更明智的决策,但是它同时也会带来许多的挑战:可用的内存可能无法足以处理大数据集,可能需要花太久的时间进行处理或可能流动太快而无法存储标准算法通常不能以合理的时间或内存来处理大数据集等等。目前没有任何一种单一方法可以处理大数据。为此,MATLAB…

    2022年5月18日
    35
  • pycharm使用远程python虚拟环境_pycharm自带python吗

    pycharm使用远程python虚拟环境_pycharm自带python吗虽然pycharm很耗内存,但这依然阻挡不了它灰常好用的优势,电脑配置不够的话建议选择19年的pycharm版本,16G的内存带2021.2.1运行起来是这样:首先确定pycharm用的是专业版,社区版不提供远程服务的功能。1.配置远程服务器信息并测试菜单栏Tools—->Deployment—->Configuration显示如下界面:新建一个连接,协议类型选择SFTP,不要选其他两种,其他两种实现的功能不一样,并且一般服务器上也不会开放21端口,SFTP使用的是

    2022年8月27日
    4
  • java开发系统架构_Java开发:ECP系统J2EE架构开发平台

    java开发系统架构_Java开发:ECP系统J2EE架构开发平台一体系结构 ECP 平台是一个基于 J2EE 架构设计的大型分布式企业协同管理平台 通过采用成熟的 J2EE 的多层企业架构体系 充分保证了系统的健壮性 开放性和扩展性 可选择部署于多种系统环境 满足不同类型 不同规模企业的需要 企业可以根据自己的实际情况构建合适的应用环境 结合操作系统 中间件平台和数据库产品 我们还可以构筑高安全 高性能 高可靠 高性价比的协同管理信息化平台 二 ECP 系统在 J2EE 架构

    2025年10月27日
    5
  • 如何利用js生成二维码_前端生成二维码

    如何利用js生成二维码_前端生成二维码问题来源最近在做一个项目,有这么个需求,通过生成二维码来实现网页的分享。问题分析脑海的第一反应,当然是用js来实现,自己手写?当然不是。解决方案使用QRCode.js。QRCode.js是一个用于生成二维码的JavaScript库。主要是通过获取DOM的标签,再通过HTML5Canvas绘制而成,不依赖任何库。QRCode.js:使用JavaScript生成二维码代码编写<!DOCTYPEhtml><htmllang=”en.

    2022年10月18日
    4

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号