• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

Good Bye 2013 D

D. New Year Letter
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, 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!
 1 #pragma comment(linker,"/STACK:102400000,102400000")
 2 #include <cstdio>
 3 #include <vector>
 4 #include <cmath>
 5 #include <stack>
 6 #include <queue>
 7 #include <cstring>
 8 #include <iostream>
 9 #include <algorithm>
10 using namespace std;
11 #define INF 0x7fffffff
12 #define mod 1000000007
13 #define ll long long
14 #define maxn 206
15 #define pi acos(-1.0)                                             
16 #define FF(i,n) for(int i=0;i<n;i++)
17 ll n, m, z, t, flag, k, x,y; 
18 ll f[maxn];
19 int main(){
20     cin >> k >> x >> n >> m;
21     for (int i = 0; i <= n / 2; i++)
22     for (int j = 0; j <= m / 2; j++)
23     for (int a = 0; a < 2; a++)
24     for (int b = 0; b < 2; b++)
25     for (int c = 0; c < 2; c++)
26     for (int d = 0; d < 2; d++){
27         if (i * 2 + a + b > n||j * 2 + c + d > m)continue;
28         f[1] = i; f[2] = j; t = 0;
29         if (b && c)t++;
30         for (z = 3; z <= k; z++){
31             f[z] = f[z - 1] + f[z - 2];
32             if (t)f[z]++, t--;
33             if (z>3&&d&&a&&z % 2 == 0)f[z]++;
34             if (z>3&&d&&c&&z % 2 == 1)f[z]++;
35         }
36         if (f[k] == x){
37             if (a)printf("C");
38             for (int z = 0; z < i; z++)printf("AC");
39             for (int z = 0; z < n-i*2-a-b; z++)printf("M");
40             if (b)printf("A"); puts("");
41             if (c)printf("C"),z++;
42             for (int z = 0; z < j; z++)printf("AC");
43             for (int z = 0; z < m-j*2-c-d; z++)printf("M");
44             if (d)printf("A"); puts("");
45             return 0;
46         }
47     }
48     printf("Happy new year!\n");
49     return 0;
50 }
View Code
posted @ 2014-01-03 16:24  HaibaraAi  阅读(112)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3