当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
Basic use of Arc GIS 2
uni-app学习总结
[MySQL] understand the important architecture of MySQL (I)
V-permission add permission
登录模块用例编写
Fiddler抓包工具之移动端抓包
After attaching to the process, the breakpoint displays "currently will not hit the breakpoint, and no symbols have been loaded for this document"
正则表达式
会议OA项目(三)---我的会议(会议排座、送审)
[Online deadlock analysis] by index_ Deadlock event caused by merge
随机推荐
模板(三)
多层嵌套后的 Fragment 懒加载实现
wap端微信h5支付,用于非微信浏览器
Force deduction brush questions, sum of three numbers
Does volatile rely on the MESI protocol to solve the visibility problem? (top)
官方颁发的SSL证书与自签名证书结合实现网站双向认证
微信小程序AvatarCropper 头像裁剪
青少年软件编程等级考试标准解读_二级
MySql5.7.25源码安装记录
dll中的全局变量
matlab simulink实现模糊pid对中央空调时延温度控制系统控制
arc-gis的基本使用2
opencv 类的使用
JS output diamond on the console
nodejs中mysql的使用
2020-12-29
When you click input, the border is not displayed!
I'm faded
EOJ 2020 1月月赛 E数的变换
[Online deadlock analysis] by index_ Deadlock event caused by merge