当前位置:网站首页>E. Two Small Strings
E. Two Small Strings
2022-07-26 09:30:00 【Run away】
Portal :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
The question
Ask string str Whether there is ,str from n individual ’a’,n individual ’b’,n individual ’c’ form , And the input length is n String st1,st2 No str The string of , If exist , Output any case .
Ideas
Just began to think for a long time , No idea , Because of the comparison of dishes , The classification point cannot be found , So I just enumerate it directly .
Enumerate a certain number of str, And then use string Of find function , If you can't find it , It outputs ,return 0; If you can't find it at last , Just NO.
If you enumerate , because str By n individual “abc” form , Then we can next_permutation, find “abc” All situations of , then n Double expansion .
#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;
}
边栏推荐
猜你喜欢
随机推荐
面试题目大赏
QT随手笔记(六)——更新界面、截图、文件对话框
php执行shell脚本
How to add a PDB
配置ADCS后访问certsrv的问题
VectorTileLayer更换style
ie7设置overflow属性失效解决方法
[untitled]
I'm faded
uni-app学习总结
大二上第一周学习笔记
服务器环境配置全过程
antd TreeSelect获取父节点的值
mfc随手笔记
官方颁发的SSL证书与自签名证书结合实现网站双向认证
附加到进程之后,断点显示“当前不会命中断点 还没有为该文档加载任何符号”
Basic use of ArcGIS 4
I'm faded
mysql5.7.25主从复制(单向)
系统安装Serv-U后IIS出错提示:HRESULT:0x80070020









