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;

bool  automaton()
{
    int i=0,j=0,flag=0;
    while(a[i]!='\0')
    {
        if(a[i]==b[j])
        {
            i++;
            j++;
            flag++;
        }
        else
        {
            i++;
        }
    }
    if(flag==lb) return true;
    return false;
}

int main()
{
    int i,j;
    int c[500],d[500];
    cin>>a;
    cin>>b;
    la=strlen(a);
    lb=strlen(b);
    if(lb>la)
    {
        printf("need tree\n");
        return 0;
    }
    if(la==lb)
    {
        memset(c,0,sizeof c);
        memset(d,0,sizeof d);
        for(i=0;i<la;i++)
            c[a[i]]++;
        for(i=0;i<lb;i++)
            d[b[i]]++;
        int ans=0;
        for(i='a';i<='z';i++)
            if(c[i]==d[i])
            ans++;
        if(ans==26)
        {
            printf("array\n");
            return 0;
        }
    }
    else if(automaton())
    {
        printf("automaton\n");
        return 0;
    }
        memset(c,0,sizeof c);
        memset(d,0,sizeof d);
        int anss=0;
        for(i=0;i<lb;i++)
            d[b[i]]++;
        for(i=0;i<la;i++)
            c[a[i]]++;
            for(i='a';i<='z';i++)
                if(d[i]!=0)
                anss++;
        int an=0;
        for(i='a';i<='z';i++)
            if(c[i]>=d[i]&&d[i]!=0)
                an++;
        //cout<<an<<" "<<anss<<endl;
        if(an==anss)
        {
            printf("both\n");
            return 0;
        }
        printf("need tree\n");

    return 0;
}

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

时间: 2024-08-07 00:11:46

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

Codeforces Round #256 (Div. 2) C (448C)Painting Fence

分治!首先是一大块,贪行刷和竖刷的最小,再转化为小块............ AC代码如下: #include<iostream> #include<cstring> #include<cstdio> using namespace std; int n; int a[5005]; int solve(int l,int r) { int i,j; int len=r-l+1; int height=a[l]; for(i=l;i<=r;i++) if(a[i]&

Codeforces Round #288 (Div. 2)B(字符串)

题意:交换两个数,使得交换后的数是偶数且尽可能大: KEY:分情况,1末尾数为偶数,即找到比它小的偶数交换,假如没有比它小的偶数,不用交换.2末尾数是奇数,再分情况,<1>全都是奇数(这个可以在一开始就判断掉),即输出-1,<2>有一个偶数,无论如何谁大谁小都要交换,<3>全部偶数都比奇数大,从n - 2(n是字符串长度)开始找到一个偶数交换即可,<4>如果有一些偶数比末尾数大,有些比它小,即从0开始找到比奇数小的那个偶数交换即可.其实是分类讨论.(有更好的

Codeforces Round #597 (Div. 2)D(最小生成树)

/*每个点自己建立一座发电站相当于向超级源点连一条长度为c[i]的边,连电线即为(k[i]+k[j])*两点间曼哈顿距离,跑最小生成树(prim适用于稠密图,kruscal适用于稀疏图)*/ #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;int fa[2007];int x[2007],y[2007];int c[2007],k[2007];long long m[2007][2007];vecto

Hot Days Codeforces Round #132 (Div. 2) D(贪婪)

Description The official capital and the cultural capital of Berland are connected by a single road running through n regions. Each region has a unique climate, so the i-th (1?≤?i?≤?n) region has a stable temperature of ti degrees in summer. This sum

Hot Days Codeforces Round #132 (Div. 2) D(贪心)

Description The official capital and the cultural capital of Berland are connected by a single road running through n regions. Each region has a unique climate, so the i-th (1?≤?i?≤?n) region has a stable temperature of ti degrees in summer. This sum

题解——Codeforces Round #508 (Div. 2) T3 (贪心)

贪心的选取最优解 然后相减好 记得要开long long #include <cstdio> #include <algorithm> #include <cstring> #include <set> #include <queue> #define int long long using namespace std; int ansa=0,ansb=0,posa=1,posb=1,n,a[1000100],b[1000100]; bool c

Codeforces Round #618 (Div. 1)C(贪心)

把所有数看作N块,后面的块比前面的块小的话就合并,这个过程可能会有很多次,因为后面合并后会把前面的块均摊地更小,可能会影响更前面地块,像是多米诺骨牌效应,从后向前推 1 #define HAVE_STRUCT_TIMESPEC 2 #include<bits/stdc++.h> 3 using namespace std; 4 double a[1000007]; 5 vector<double>vv[1000007]; 6 int main(){ 7 //ios::sync_wi

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]的区间,答案不