【题目链接】: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. BZOJ 1396 识别子串 (后缀自动机+线段树)

    题目大意: 给你一个字符串S,求关于每个位置x的识别串T的最短长度,T必须满足覆盖x,且T在S中仅出现一次 神题 以节点x为结尾的识别串,必须满足它在$parent$树的子树中只有一个$endpos$ ...

  2. JS数据分组[JSON]

    JS 数据分组 var arr = [{ "id": "1001", "name": "值1", "value ...

  3. thinkPHP利用ajax异步上传图片并显示、删除

    近来学习tp5的过程中,项目中有个发帖功能,选择主题图片.如下: 利用原始的文件上传处理,虽然通过原始js语句能实时显示上传图片,但是这样的话会涉及很多兼容问题.使用ajax技术,实现选择性删除所选图 ...

  4. v4l2程序实例

    #include <stdio.h> #include <string.h> #include <errno.h> #include <stdlib.h> ...

  5. tomcat闪退无法启动 the catalina_home environment variable is not defined correctly this environment variable is needed to run this program

    未成功配置CATALINA_HOME 1.计算机>属性>环境变量, 新建环境变量.变量名为CATALINA_HOME ,变量值tomcat的解压目录,注意后面不用多加“\”或者“;” 2. ...

  6. WEB开发兼容性---浏览器渲染模式—— document.compatMode

    document.compatMode主要是用来判断浏览器采用何种方式渲染,它有两种可能的返回值:BackCompat和CSS1Compat,官方对其解释如下: BackCompat:标准兼容模式关闭 ...

  7. Mybatis 中 foreach collection 的三种用法

    foreach的主要用在构建in条件中,它可以在SQL语句中进行迭代一个集合. foreach元素的属性主要有 item,index,collection,open,separator,close. ...

  8. jquery访问ashx文件示例

    转自原文jquery访问ashx文件示例 .ashx 文件用于写web handler的..ashx文件与.aspx文件类似,可以通过它来调用HttpHandler类,它免去了普通.aspx页面的控件 ...

  9. spring boot和maven的约定大于配置体现在哪些方面

    spring boot和maven的约定大于配置体现在哪些方面? 两者都遵从了约定大于配置的路线 约定优于配置体现点: 1.maven的目录文件结构 1)默认有resources文件夹,存放资源配置文 ...

  10. [debug]重定义默认參数

    编敲代码过程中遇到重定义默认參数的错误,例如以下例所看到的: #include<iostream> #include<stdlib.h> using namespace std ...