E. Two Small Strings

传送门:http://codeforces.com/problemset/problem/1213/E

You are given two strings s and t both of length 2 and both consisting only of characters ‘a’, ‘b’ and ‘c’.
Possible examples of strings s and t: “ab”, “ca”, “bb”.
You have to find a string res consisting of 3n characters, n characters should be ‘a’, n characters should be ‘b’ and n characters should be ‘c’ and s and t should not occur in res as substrings.
A substring of a string is a contiguous subsequence of that string. So, the strings “ab”, “ac” and “cc” are substrings of the string “abacc”, but the strings “bc”, “aa” and “cb” are not substrings of the string “abacc”.
If there are multiple answers, you can print any of them.

Input

The first line of the input contains one integer n (1≤n≤105) — the number of characters ‘a’, ‘b’ and ‘c’ in the resulting string.
The second line of the input contains one string s of length 2 consisting of characters ‘a’, ‘b’ and ‘c’.
The third line of the input contains one string t of length 2 consisting of characters ‘a’, ‘b’ and ‘c’.

Output

If it is impossible to find the suitable string, print “NO” on the first line.
Otherwise print “YES” on the first line and string res on the second line. res should consist of 3n characters, n characters should be ‘a’, n characters should be ‘b’ and n characters should be ‘c’ and s and t should not occur in res as substrings.
If there are multiple answers, you can print any of them.

Examples

input
2
ab
bc
output
YES
acbbac

input
3
aa
bc
output
YES
cacbacbab

input
1
cb
ac
output
YES
abc

题意

  询问字符串 str 是否存在,str 由 n 个’a’,n 个’b’,n 个’c’ 组成,并且输入的长度为 n 的字符串 st1,st2 不是 str 的子串,若存在,输出任意情况。

思路

  才开始想了好久,没有思路,因为比较菜的缘故,找不到分类点,所以就直接暴力枚举了。
  枚举一定数量的 str,然后用 string 的 find 函数,都找不到的话,就输出,return 0;最后找不到的话,就 NO。
  枚举的话,因为 str 是由 n 个“abc” 组成,那我们可以 next_permutation,找出“abc”的所有情况,然后 n 倍扩张即可。

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
#include<ctime>
#include<utility>
#include<map>
#define ll long long
#define ld long double
#define ull unsigned long long
using namespace std;
typedef pair<int,int> P;
const int INF = 0x3f3f3f3f3f;
const ll LNF = 0x3f3f3f3f3f3f3f;
const double eps = 1e-6;
const int maxn = 150010;
string abc = "abc";
string st1,st2;
vector<string> st;
int main(void)
{
    int n;
    cin>>n>>st1>>st2;
    
    do{
        string st3;
        for(int i=0;i<n;i++)
            st3 += abc;
        st.push_back(st3);
        st.push_back(string(n,abc[0])+string(n,abc[1])+string(n,abc[2]));
    }while(next_permutation(abc.begin(),abc.end()));
    
    vector<string>::iterator it = st.begin();
    while(it!=st.end()){
        string st4 = *it;
        if(st4.find(st1)==-1&&st4.find(st2)==-1){
            printf("YES\n");
            cout<<st4<<endl;
            return 0;
        }
        it++;
    }
    printf("NO\n");

    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

逃夭丶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值