当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
随机推荐
keepalived 实现mysql自动故障切换
v-premission添加权限
Arc GIS basic operation 3
微信小程序学习笔记1
Force button list question
解决“NOTE: One or more layouts are missing the layout_width or layout_height attributes.”
E. Two Small Strings
asp. Net using redis cache (2)
设置视图动态图片
Qt随手笔记(二)Edit控件及float,QString转化、
小白搞一波深拷贝 浅拷贝
省政府召开全省高温天气安全防范工作电视电话会议
安卓 实现缓存机制,多种数据类型缓存
微信小程序开发
学习笔记之常用数组api 改变原数组和不改变原数组的有哪些?
matlab中的AR模型短时预测交通流
调用DLL开启线程的问题
M-ary number STR to n-ary number
Windows下Redis哨兵模式搭建
OpenCV 表格识别之表格提取(二)








![[MySQL] understand the important architecture of MySQL (I)](/img/89/5fb595b0112fac987626857b76f9a4.png)
