首页 技术 正文
技术 2022年11月11日
0 收藏 935 点赞 3,495 浏览 3333 个字

D. New Year Lettertime limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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, s1 anf s2, consisting of uppercase English letters. Then the boy makes string sk, using a recurrent equation sn = sn - 2 + sn - 1, 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 s1 should have length n, and string s2 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, s1 and s2 in the required manner. Help Vasya.

Input

The first line contains four integers k, x, n, m (3 ≤ k ≤ 50; 0 ≤ x ≤ 109; 1 ≤ n, m ≤ 100).

Output

In the first line print string s1, consisting of n uppercase English letters. In the second line print string s2, 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.

Sample test(s)Input

3 2 2 2

Output

AC AC

Input

3 3 2 2

Output

Happy new year!

Input

3 0 2 2

Output

AA AA

Input

4 3 2 1

Output

Happy new year!

Input

4 2 2 1

Output

Happy new year!题意:转自 http://www.cnblogs.com/wuminye/p/3500422.html

【题目大意】

告诉你初始字符串S1、S2的长度和递推次数k, 使用类似斐波纳契数列的字符串合并的递推操作,使得最后得到的字符串中刚好含有x个”AC”,现在要你构造出满足条件的S1和S2。

【分析】

最终结果中有些”AC”可能是应为在合并时一个字符串的尾部和另一个字符串的首部合并而成,这就跟原始字符串的首尾字符有关,不同的情况在K次递推后多产生的”AC”数是不同的,所以这里既要枚举下初始串的首尾字符,计算出因合并产生的”AC”数sum有多少。

现在可以忽略合并产生的”AC”了,假设S1中有a个”AC”,S2中有b个”AC”,则经过k次递推由这些”AC”组合成的”AC”数量为:fib[k-2]*a+fib[k-1]*b。

所以最终的结果为:

f[k]=fib[k-2]*a+fib[k-1]*b+sum;

f[k]=x 已知,sum可以枚举获得 ,于是只需枚举a 即可知道 a和b 的值,对于一组 a,b值看能否构造出符合条件的字符串就好了。

其实可以不用枚举a,用不定方程来解就好了,当a,b很大时速度更快。

 #include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map> #define N 105
#define M 15
#define mod 1000000007
#define mod2 100000000
#define ll long long
#define maxi(a,b) (a)>(b)? (a) : (b)
#define mini(a,b) (a)<(b)? (a) : (b) using namespace std; int k,n,m;
ll f[N];
int l[N];
int r[N];
ll z;
ll x;
void ini()
{
//k=0;
//memset(next,0,sizeof(next));
// memset(nexta,0,sizeof(nexta));
} void solve()
{ } int main()
{
int i,j;
int a,b,c,d;
int o,p;
//freopen("data.in","r",stdin);
// scanf("%d",&T);
// for(int cnt=1;cnt<=T;cnt++)
//while(T--)
while(scanf("%d%I64d%d%d",&k,&x,&n,&m)!=EOF)
{
for(i=;i<=n/;i++)
{
for(j=;j<=m/;j++)
{
for(a=;a<;a++)
for(b=;b<;b++)
for(c=;c<;c++)
for(d=;d<;d++)
{
if (i * + a + b > n||j * + c + d > m)continue;
f[]=i;f[]=j;f[]=i+j;l[]=c;r[]=d;
if(b== && c==) f[]++;
l[]=a;r[]=d;
for(z=;z<=k;z++){
f[z]=f[z-]+f[z-];
l[z]=l[z-];
r[z]=r[z-];
if(r[z-]== && l[z-]==) f[z]++;
} // printf(" i=%d %d %d %d %d d=%d f=%I64d\n",i,j,a,b,c,d,f[k]);
if(f[k]==x){
if(a==) printf("C");
for(o=;o<=i;o++){
printf("AC");
}
for(p=a+i*;p<n-b;p++){
printf("M");
}
if(b==) printf("A");
printf("\n"); if(c==) printf("C");
for(o=;o<=j;o++){
printf("AC");
}
for(p=c+j*;p<m-d;p++){
printf("M");
}
if(d==) printf("A");
printf("\n");
return ;
}
}
}
}
printf("Happy new year!\n");
//ini();
// solve();
// printf("%I64d\n",ans);
} return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,031
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,520
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,368
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,148
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,781
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,860