D. New Year Letter
time 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 ;
}

CodeForces 379D 暴力 枚举的更多相关文章

  1. Codeforces Round #349 (Div. 1) B. World Tour 最短路+暴力枚举

    题目链接: http://www.codeforces.com/contest/666/problem/B 题意: 给你n个城市,m条单向边,求通过最短路径访问四个不同的点能获得的最大距离,答案输出一 ...

  2. Codeforces Round #298 (Div. 2) B. Covered Path 物理题/暴力枚举

    B. Covered Path Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/534/probl ...

  3. Codeforces 425A Sereja and Swaps(暴力枚举)

    题目链接:A. Sereja and Swaps 题意:给定一个序列,能够交换k次,问交换完后的子序列最大值的最大值是多少 思路:暴力枚举每一个区间,然后每一个区间[l,r]之内的值先存在优先队列内, ...

  4. CodeForces 742B Arpa’s obvious problem and Mehrdad’s terrible solution (暴力枚举)

    题意:求定 n 个数,求有多少对数满足,ai^bi = x. 析:暴力枚举就行,n的复杂度. 代码如下: #pragma comment(linker, "/STACK:1024000000 ...

  5. D. Diverse Garland Codeforces Round #535 (Div. 3) 暴力枚举+贪心

    D. Diverse Garland time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  6. Codeforces Round #266 (Div. 2)B(暴力枚举)

    很简单的暴力枚举,却卡了我那么长时间,可见我的基本功不够扎实. 两个数相乘等于一个数6*n,那么我枚举其中一个乘数就行了,而且枚举到sqrt(6*n)就行了,这个是暴力法解题中很常用的性质. 这道题找 ...

  7. Codeforces Round #253 (Div. 2)B(暴力枚举)

    就暴力枚举所有起点和终点就行了. 我做这题时想的太多了,最简单的暴力枚举起始点却没想到...应该先想最简单的方法,层层深入. #include<iostream> #include< ...

  8. Codeforces Round #325 (Div. 2) B. Laurenty and Shop 有规律的图 暴力枚举

    B. Laurenty and Shoptime limit per test1 secondmemory limit per test256 megabytesinputstandard input ...

  9. Gym 101194L / UVALive 7908 - World Cup - [三进制状压暴力枚举][2016 EC-Final Problem L]

    题目链接: http://codeforces.com/gym/101194/attachments https://icpcarchive.ecs.baylor.edu/index.php?opti ...

随机推荐

  1. firstElectron_web5 安装

    小娜 搜 cmd 右键 管理员运行 1.装全局 这样 不用每次都下载 因为包挺大的 还有用cnpm 要不太慢 cnpm install electron --save-dev --save-exact ...

  2. caffe的调试技巧 和 使用split层

    1.网络中的layer层的输出,只要没有作为其他层的输入,caffe的日志就会把这个top输出(如果你用那个网站画网络结构图,你也会发现这种情况的层的颜色是不一样的,是紫色的) 2.如果你想看某一层在 ...

  3. 小白安装python软件

    首先下载:anaconda3.x          下载方式:百度搜索 清华镜像anaconda   https://mirrors.tuna.tsinghua.edu.cn/help/anacond ...

  4. 伪题解 洛谷 P1363 幻想迷宫(DFS)

    毒瘤题,做了一晚上抄题解A了 因为是抄题解,我也不好意思说什么了,就发篇博客纪念一下吧 #include<iostream> #include<cstring> #includ ...

  5. shell脚本,判断给出的字符串是否相等。

    第一种方法[root@localhost wyb]# .sh #!/bin/bash #判断给出的字符串是否相等 read -p "Please Input a number:" ...

  6. 【译】Swift 字符串速查表

    [译]Swift 字符串速查表 2015-12-18 10:32 编辑: suiling 分类:Swift 来源:CocoaChina翻译活动 10 5585 Swift字符串 招聘信息: iOS高级 ...

  7. ccf_201712-2

    题目 问题描述 有n个小朋友围成一圈玩游戏,小朋友从1至n编号,2号小朋友坐在1号小朋友的顺时针方向,3号小朋友坐在2号小朋友的顺时针方向,……,1号小朋友坐在n号小朋友的顺时针方向. 游戏开始,从1 ...

  8. Educational Codeforces Round 40千名记

    人生第二场codeforces.然而遇上了Education场这种东西 Educational Codeforces Round 40 下午先在家里睡了波觉,起来离开场还有10分钟. 但是突然想起来还 ...

  9. [CODEVS] 2189 数字三角形W

    数字三角形 要求走到最后mod 100最大 可达性DP(好像是这样叫) 用bool数组f[i][j][k]表示 位置(i,j)能否得到k(mod 100意义下) 转移条件 f[i][j][k]=f[i ...

  10. windows 7虚拟机与主机不能互ping通,但是都能与网关ping通

    这里是在Windows 10的环境下使用VMware安装了一个Windows 7的虚拟机,虚拟机中是使用桥接的方式.结果发现虚拟机不能与物理机互通,但是却能与网关互通.查看虚拟机和物理机的IP发现都是 ...