首页 > 其他 > 详细

E - Eva and Euro coins

时间:2019-10-19 16:28:25      阅读:62      评论:0      收藏:0      [点我收藏+]

题目链接: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\n");
    else printf("No\n");
    return 0;
}

 

E - Eva and Euro coins

原文:https://www.cnblogs.com/caijiaming/p/11704000.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!