time limit per test:1 second
memory limit per test:256 megabytes
Many countries have such a New Year or Christmas tradition as writing a letter to Santa including a wish list for presents. Vasya is an ordinary programmer boy. Like all ordinary boys, he is going to write the letter to Santa on the New Year Eve (we Russians actually expect Santa for the New Year, not for Christmas).
Vasya has come up with an algorithm he will follow while writing a letter. First he chooses two strings, anf , consisting of uppercase English letters. Then the boy makes string sk, using a recurrent equation , operation ‘+’ means a concatenation (that is, the sequential record) of strings in the given order. Then Vasya writes down string sk on a piece of paper, puts it in the envelope and sends in to Santa.
Vasya is absolutely sure that Santa will bring him the best present if the resulting string sk has exactly x occurrences of substring AC
(the short-cut reminds him оf accepted problems). Besides, Vasya decided that string
should have length n, and string
should have length m. Vasya hasn’t decided anything else.
At the moment Vasya’s got urgent New Year business, so he asks you to choose two strings for him, and in the required manner. Help Vasya.
Input
The first line contains four integers .
Output
In the first line print string , consisting of uppercase English letters. In the second line print string , consisting of m uppercase English letters. If there are multiple valid strings, print any of them.
If the required pair of strings doesn’t exist, print "Happy new year!"
without the quotes.
Examples
Input1
3 2 2 2
Output1
AC
AC
Input2
3 3 2 2
Output2
Happy new year!
Input3
3 0 2 2
Output3
AA
AA
Input4
4 3 2 1
Output4
Happy new year!
Input5
4 2 2 1
Output5
Happy new year!
题意:
给一个字符串生成方式:
,然后询问,如果要使得
中子串AC
的数量刚好为
,
,
分别是多少,
,
长度刚好分别为
,
。
题解:
枚举
,
中的子串AC
数量、开头字母、结尾字母,然后
判断
中的子串数量就行了。
#include<bits/stdc++.h>
#define LiangJiaJun main
#define ll long long
using namespace std;
int k,x,n,m;
struct S{
int f,b;
ll cnt;
}a[54];
int l[54];
char s[4][104];
bool check(int x){
if(a[x].f==1)s[x][1]='A';
if(a[x].f==2)s[x][1]='C';
if(a[x].f==3)s[x][1]='B';
if(a[x].b==1)s[x][l[x]]='A';
if(a[x].b==2)s[x][l[x]]='C';
if(a[x].b==3)s[x][l[x]]='B';
if(l[x]==1&&a[x].f!=a[x].b)return 0;
if(l[x]==2&&a[x].f==1&&a[x].b==2&&a[x].cnt!=1)return 0;
if(l[x]==2&&a[x].f==a[x].b&&a[x].cnt!=0)return 0;
if(l[x]==2&&a[x].f==2&&a[x].b==1&&a[x].cnt!=0)return 0;
if(a[x].cnt==0){
for(int i=2;i<l[x];i++)s[x][i]='B';
return 1;
}
int cnt=0;
int bg;
if(s[x][1]=='A')bg=1;
else bg=2;
while(bg<l[x]&&cnt<a[x].cnt){
s[x][bg]='A';
if(bg+1==l[x]){
if(s[x][l[x]]!='C')return 0;
else s[x][l[x]]='C';
}
else s[x][bg+1]='C';
++cnt;
bg+=2;
}
for(int i=bg;i<l[x];i++)s[x][bg]='B';
return (cnt==a[x].cnt);
}
void output(){
for(int i=1;i<=2;i++){
for(int j=1;j<=l[i];j++)printf("%c",s[i][j]);
puts("");
}
return ;
}
int w33ha(){
l[1]=n;
l[2]=m;
for(int i=0;i<=n/2;i++){
for(int j=0;j<=m/2;j++){
for(int o=1;o<=3;o++){
for(int p=1;p<=3;p++){
for(int q=1;q<=3;q++){
for(int r=1;r<=3;r++){
a[1].f=o;
a[1].b=p;
a[1].cnt=i;
a[2].f=q;
a[2].b=r;
a[2].cnt=j;
if(check(1)&&check(2)){
bool flag=1;
for(int y=3;y<=k;y++){
a[y].f=a[y-2].f;
a[y].b=a[y-1].b;
if(a[y-2].b==1&&a[y-1].f==2){
a[y].cnt=1;
}
else a[y].cnt=0;
a[y].cnt+=a[y-2].cnt+a[y-1].cnt;
if(a[y].cnt>(1LL*x)){
flag=0;
break;
}
}
if(!flag)continue;
if(a[k].cnt==(1LL*x)){
output();
return 0;
}
}
}
}
}
}
}
}
puts("Happy new year!");
return 0;
}
int LiangJiaJun(){
while(scanf("%d%d%d%d",&k,&x,&n,&m)!=EOF)w33ha();
return 0;
}