【题目链接】:http://codeforces.com/contest/379/problem/D

【题意】



让你构造出两个长度分别为n和m的字符串s[1]和s[2]

然后按照连接的规则,顺序连接s[n-2]和s[n-1]得到s[n]

(n>=3)

即s[n] = s[n-2]+s[n-1]

以此规则得到s[k];

要求s[k]恰好出现x个“AC”子串;

【题解】



暴力题;

枚举s1有ac1个”AC”子串,s2有ac2个”AC”子串;

这里只有字符串的尾部为A且下一个字符串的头部为C才能富裕出一个“AC”子串;

则我们再枚举两个字符串的头尾;

即头部要不要加一个’C’以及尾部要不要加一个’A’;

看看符不符合长度要求;

符合长度要求;

就根据ac个数,以及两个字符串的头尾,递推到s[k];

得到s[k]的ac个数;

是x的话就输出结果;

(空出来的部分用’X’填就好)



【Number Of WA】



1



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0),cin.tie(0) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 110; LL k,x,n,m; LL check2(int now,LL ac1,LL ac2,int st1,int en1,int st2,int en2){
if (ac2>x) return ac2;
if (now==k) return ac2;
return check2(now+1,ac2,ac1 + ac2 + ( (en1 && st2)?1:0),st2,en2,st1,en2);
} bool check(LL ac1,LL ac2,int st1,int en1,int st2,int en2){
if (ac1*2 + st1 + en1>n) return false;
if (ac2*2 + st2 + en2>m) return false;
if (check2(2,ac1,ac2,st1,en1,st2,en2)==x) return true;
return false;
} string create(int ac,int st,int en,int len){
string s;
s.resize(len);
int l = 0;
if (st) s[l++] = 'C';
if (en) s[--len] = 'A';
while (ac--){
s[l++] = 'A';
s[l++] = 'C';
}
while (l<len) s[l++] = 'X';
return s;
} int main(){
//Open();
Close();
cin >> k >> x >> n >> m;
rep1(ac1,0,n/2)
rep1(ac2,0,m/2)
rep1(i,0,15)
if (check(ac1,ac2,(i&1)>0,(i&2)>0,(i&4)>0,(i&8)>0)){
cout << create(ac1,(i&1)>0,(i&2)>0,n) << endl;
cout << create(ac2,(i&4)>0,(i&8)>0,m) << endl;
return 0;
}
cout <<"Happy new year!"<<endl;
return 0;
}

【codeforces 379D】New Year Letter的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【19.77%】【codeforces 570D】Tree Requests

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. 【codeforces 742C】Arpa's loud Owf and Mehrdad's evil plan

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  4. 【codeforces 757A】Gotta Catch Em' All!

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  5. 【codeforces 754B】 Ilya and tic-tac-toe game

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. 【codeforces 761C】Dasha and Password(动态规划做法)

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  7. 【codeforces 761C】Dasha and Password(贪心+枚举做法)

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. 【codeforces 766C】Mahmoud and a Message

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. 【75.28%】【codeforces 764B】Decoding

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

随机推荐

  1. freeswitch 编码协商

    编辑 /usr/local/freeswitch/conf/sip_profiles/internal.xml 添加注释     <param name="inbound-zrtp-p ...

  2. qml与c++混合编程

    QML 与 C++ 混合编程内容:1. QML 扩展2. C++ 与 QML 交互3. 开发时要尽量避免使用的 QML 元素4. demo 讲解5. QML 语法C++ 与 QML 的交互是通过注册 ...

  3. windows server 2008开机自动登陆无密码,关机不必写原因

    运行secpol.sec接下来,在弹出的“本地安全策略”对话框中,依次展开左边树图到“本地策略”-“安全选项”,在右边可以找到“交互式登录 无须按 Ctrl+Alt+Del”,双击该项设置为“已启用” ...

  4. iOS开发自己定义键盘回车键Return Key

    在iOS开发中.用户在进行文本输入的时候,往往会用到虚拟键盘上的回车键,也就是Return Key.回车键有时候能够是"完毕"(表示输入结束).能够是"下一项" ...

  5. scp报错:Host key verification failed. REMOTE HOST IDENTIFICATION HAS CHANGED!

    1 scp报错:REMOTE HOST IDENTIFICATION HAS CHANGED! [root@xx ~]# scp yum-3.4.3.tar.gz 10.xx.xx.12:/root ...

  6. C++基础学习教程(三)

    承接上一讲. 2.7文件I/O 关于读写文件,C++中有一个专门的头文件<fstream>. 首先是读文件演示样例,例如以下: </pre><pre> /***** ...

  7. 【Linux驱动】TQ2440 DM9000E网卡驱动移植(Linux-2.6.30.4)

    花了一天的时间研究了一下Linux-2.6.30.4版本号内核下关于TQ2440 DM9000E的网卡驱动移植.总结一下自己的收获. 事实上.在Linux-2.6.30.4版本号内核下有关于网卡驱动, ...

  8. kentico version history and upgrade

    Version history Kentico 10: November 30, 2016 Kentico 9: November 24, 2015 Kentico 8.2: January 6, 2 ...

  9. hpuoj--1287--HH实习(斐波那契数巧用)

    问题 D: HH实习 时间限制: 1 Sec  内存限制: 128 MB 提交: 53  解决: 37 [提交][状态][讨论版] 题目描述 这学期到了十五周了,HH突然要去实训中心实习了,想到要拿着 ...

  10. spring boot多数据源配置示例

    1. application.properties #\u4E3B\u5E93\u914D\u7F6E spring.datasource.primary.url=jdbc:mysql://mysql ...