• E


    题目链接:http://codeforces.com/gym/101981/attachments

    题目大意:输入两个串 问你第一个串能不能转化为第二个串,翻转次数无限制,但是每次只能翻转K个连续相同的字母

    思路:找到两个串中连续的相等的K个字符,可以把他们提到串的最前面(也可以全部消掉,因为不管位置在哪,都可以通过翻转移位到同一个位置),

    全变为0(1也可以) 最后判断剩下的是否相等

    看代码:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<cmath>
    #include<vector>
    #include<map>
    #include<cstdlib>
    #include<stack>
    using namespace std;
    typedef long long LL;
    const LL mod=1e9+7;
    const LL INF=1e9+7;
    const int maxn=1e6+50;
    int a[maxn],sum[maxn];
    string solve(string s,int k)
    {
        string res="";
        stack<char> s1;
        stack<int> num;
        int len=s.size();
        for(int i=0;i<len;i++)
        {
            if(s1.empty()||s1.top()!=s[i])//为空或者最后一个不相等
            {
                s1.push(s[i]);
                num.push(1);
            }
            else//相等
            {
                int temp=num.top();
                num.pop();
                num.push(temp+1);
            }
            if(num.top()==k)//有连续的k个
            {
                num.pop();
                s1.pop();
            }
        }
        while(!s1.empty())
        {
            char c=s1.top();
            s1.pop();
            int p=num.top();
            num.pop();
            for(int i=1;i<=p;i++) res+=c;
        }
        return res;
    }
    int main()
    {
        int N,K;scanf("%d%d",&N,&K);
        int flag=0;
        string s,t;
        cin>>s>>t;
        string s1=solve(s,K);
        string s2=solve(t,K);
        if(s1==s2) printf("Yes
    ");
        else printf("No
    ");
        return 0;
    }
    当初的梦想实现了吗,事到如今只好放弃吗~
  • 相关阅读:
    repeater 设置分页
    table表格合并
    repeater分页
    http错误500.19 错误代码 0x80070021
    asp文件上传和下载
    asp:Repeater控件使用
    vs2013标签
    "Uncaught SyntaxError: Unexpected token <"错误完美解决
    监控系统说明文档
    限制input输入类型(多种方法实现)
  • 原文地址:https://www.cnblogs.com/caijiaming/p/11704000.html
Copyright © 2020-2023  润新知