【题目链接】: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. IOS - CoreData 增删改查

    #pragma mark - Core Data Methods - (void)insertObjectWithFileName:(NSString *)fileName { /** SQL新增记录 ...

  2. 使用sourceMap文件定位小程序错误信息

    sourceMap是什么 在前端开发过程中代码难免会有错误,即便是再小心,也有可能出现 Cannot read property 'xxx' of null 这样的低级失误,debug自然是家常便饭. ...

  3. systemctl 控制单元

    [root@web01 ~]# systemctl status sshd.service ● sshd.service - OpenSSH server daemon Loaded: loaded ...

  4. 实现双向数据绑定mvvm

    实现双向数据绑定mvvm  

  5. input输入框获取焦点是背景黄色去除

    input:-webkit-autofill { -webkit-box-shadow: 0 0 0px 1000px white inset !important;}

  6. 【 【henuacm2016级暑期训练】动态规划专题 P】Animals

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 第i只动物如果饲养它的话. 代价是固定的就是(n-i+1)a[i] 所以相当于给你n个物品,每个物品的重量为(n-i+1)a[i], ...

  7. 【codeforces 501D】Misha and Permutations Summation

    [题目链接]:http://codeforces.com/problemset/problem/501/D [题意] 给你两个排列; 求出它们的字典序num1和num2; 然后让你求出第(num1+n ...

  8. 纯粹的K12精髓 - 名师指导整理《20以内加法口诀表》

    纯粹的K12精髓 - 名师指导整理<20以内加法口诀表> 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一 ...

  9. Win7上从硬盘安装Debian

    近期一直想将笔记本搞成Win7+Debian双系统.由于无论怎样优化,2G内存的Win7笔记本上开个Linux虚拟机都实在吃力. 经过一段时间的资料搜索.并阅读Debian官方的安装文档,今天最终实现 ...

  10. jQuery Mobile(jqm)button的隐藏和显示,包含a标签,圆角和非圆角button

    在移动互联网时代,HTML5开发越来越收到欢迎. 于是各种HTML5的框架都出来了.因为对于jquery的熟悉,jquery mobile 为多数人选择学习的对象.我也是众多追求者之中的一个.近期一直 ...