B. Obtaining the String(模拟)

Posted alingmaomao

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了B. Obtaining the String(模拟)相关的知识,希望对你有一定的参考价值。

比较水的模拟

思路:就是模拟题意

注意:把数组开大点,开始wa了几次就是这个原因

#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
string a, b;
int aa[100000], t, n;
bool flag1;

int main(){
    cin>>n;
    cin>>a>>b;
    int p=0, q=0;
    while(q<n){
        bool flag=0;
        while(q<n&&a[p]==b[q]){++p; ++q;}
        while(p<n&&a[p]!=b[q]){++p; flag=1;}
        if(flag&&p==n){flag1=1; break;}
        for(int i=p;i>q;--i){
            swap(a[i], a[i-1]);   aa[t++]=i;
        }
        p=q;
    }
    if(flag1)cout<<-1<<endl;
    else {
        cout<<t<<endl;
        for(int i=0;i<t;++i)
            cout<<aa[i]<<" ";
        cout<<endl;
    }

}

 

以上是关于B. Obtaining the String(模拟)的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #501 (Div. 3) B Obtaining the String

Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool

SQLSERVER:Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool.

Codeforces Gym 101174 I The White Rabbit Pocket Watch 模线性方程组

Codeforces1103 B. Game with modulo(取模性质,二分)

Round #427 B. The number on the board(Div.2)