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. 与调试器共舞 - LLDB 的华尔兹

    你是否曾经苦恼于理解你的代码,而去尝试打印一个变量的值? 1 NSLog(@"%@", whatIsInsideThisThing); 或者跳过一个函数调用来简化程序的行为? 1 ...

  2. 通过例子理解 k8s 架构【转】

    为了帮助大家更好地理解 Kubernetes 架构,我们部署一个应用来演示各个组件之间是如何协作的. 执行命令 kubectl run httpd-app --image=httpd --replic ...

  3. caffe修改需要的东西 6:40

    https://blog.csdn.net/zhaishengfu/article/details/51971768?locationNum=3&fps=1

  4. JavaScript中的显示原型和隐形原型(理解原型链)

    显式原型:prototype 隐式原型:__proto__ 1.显式原型和隐式原型是什么? 在js中万物皆对象,方法(Function)是对象,方法的原型(Function.prototype)是对象 ...

  5. CVE-2010-3333

    环境 windows xp sp3 office 2003 sp0 windbg ollydbg vmware 12.0 0x00 RTF格式 RTF是Rich TextFormat的缩写,意即富文本 ...

  6. POI转换word doc文件为(html,xml,txt)

    在POI中还存在有针对于word doc文件进行格式转换的功能.我们可以将word的内容转换为对应的Html文件,也可以把它转换为底层用来描述doc文档的xml文件,还可以把它转换为底层用来描述doc ...

  7. oracle count 百万级 分页查询记要总数、总条数优化

    oracle count 百万级 分页查询记录总数.总条数优化 oracle count 百万级 查询记录总数.总条数优化 最近做一个项目时,做分页时,发现分页查询速度很慢,分页我做的是两次查询,一次 ...

  8. 升级nodejs 与短小的n模块

    要用指令升级nodejs到新版本要先安装n模块 window用不了n模块  可以用 nvm-windows : https://github.com/coreybutler/nvm-windows n ...

  9. 组合的输出(DFS)

    题目描述: 排列与组合是常用的数学方法,其中组合就是从n个元素中抽出r个元素(不分顺序且r<=n),我们可以简单地将n个元素理解为自然数1,2,…,n,从中任取r个数. 现要求你用递归的方法输出 ...

  10. (42)zabbix使用IT services 了解服务器SLA整体情况

    什么是IT Services 服务器或者某项服务.业务的可用率,不懂技术的上级领导会过问最近服务器可用率如何.所有api的状况怎么样? 通常一些技术人员会说负载怎么样,哪些cpu使用率怎么样,硬盘使用 ...