【题目链接】: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



【完整代码】

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define lson l,m,rt<<1
  4. #define rson m+1,r,rt<<1|1
  5. #define LL long long
  6. #define rep1(i,a,b) for (int i = a;i <= b;i++)
  7. #define rep2(i,a,b) for (int i = a;i >= b;i--)
  8. #define mp make_pair
  9. #define pb push_back
  10. #define fi first
  11. #define se second
  12. #define ms(x,y) memset(x,y,sizeof x)
  13. #define Open() freopen("F:\\rush.txt","r",stdin)
  14. #define Close() ios::sync_with_stdio(0),cin.tie(0)
  15. typedef pair<int,int> pii;
  16. typedef pair<LL,LL> pll;
  17. const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
  18. const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
  19. const double pi = acos(-1.0);
  20. const int N = 110;
  21. LL k,x,n,m;
  22. LL check2(int now,LL ac1,LL ac2,int st1,int en1,int st2,int en2){
  23. if (ac2>x) return ac2;
  24. if (now==k) return ac2;
  25. return check2(now+1,ac2,ac1 + ac2 + ( (en1 && st2)?1:0),st2,en2,st1,en2);
  26. }
  27. bool check(LL ac1,LL ac2,int st1,int en1,int st2,int en2){
  28. if (ac1*2 + st1 + en1>n) return false;
  29. if (ac2*2 + st2 + en2>m) return false;
  30. if (check2(2,ac1,ac2,st1,en1,st2,en2)==x) return true;
  31. return false;
  32. }
  33. string create(int ac,int st,int en,int len){
  34. string s;
  35. s.resize(len);
  36. int l = 0;
  37. if (st) s[l++] = 'C';
  38. if (en) s[--len] = 'A';
  39. while (ac--){
  40. s[l++] = 'A';
  41. s[l++] = 'C';
  42. }
  43. while (l<len) s[l++] = 'X';
  44. return s;
  45. }
  46. int main(){
  47. //Open();
  48. Close();
  49. cin >> k >> x >> n >> m;
  50. rep1(ac1,0,n/2)
  51. rep1(ac2,0,m/2)
  52. rep1(i,0,15)
  53. if (check(ac1,ac2,(i&1)>0,(i&2)>0,(i&4)>0,(i&8)>0)){
  54. cout << create(ac1,(i&1)>0,(i&2)>0,n) << endl;
  55. cout << create(ac2,(i&4)>0,(i&8)>0,m) << endl;
  56. return 0;
  57. }
  58. cout <<"Happy new year!"<<endl;
  59. return 0;
  60. }

【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. CF343E Pumping Stations(最小割树)

    没学过最小割树的出门左转. 我们已经知道了两点的最小割就是最小割树上,对应两点之间路径的权值的最小值. 找到最小割树中权值的最小的边. 那么一定是先选完一侧的点在选完另一侧的点. 因为当前边最小,那么 ...

  2. hadoop中HDFS文件系统 nameNode出现的问题 nameNode无法打开

    1,修改core-site.xml文件,先改成localhost,将所有进程关闭stop-all.sh(或者是先关闭所有进程,然后再修改文件),然后重启,在修改core-site.xml文件成ip地址 ...

  3. VUE:渐进式JavaScript框架(小白自学)

    VUE:渐进式JavaScript框架 一.官网 英文 https://vuejs.org/ 中文 https://cn.vuejs.org/ 二:渐进式 即有一个核心库,在需要的时候再逐渐添加插件的 ...

  4. ASP.NET-HTTP响应标头

    Reponse Headers 理论上所有的响应头信息都应该是回应请求头的.但是服务端为了效率,安全,还有其他方面的考虑,会添加相对应的响应头信息,从上图可以看到: Cache-Control:mus ...

  5. ASP.NET-优化websit

    如何优化一个网站 1.如果是数据库的问题则尝试添加索引.优化SQL语句,如果是算法的问题,则优化算法. 2.如果对于一些不经常改动的页面可以使用静态页技术! 3.对于一些数据不需要及时更新的而且取数据 ...

  6. aliyun Ubuntu 14.04 64bit OpenJDK Tomcat7 install

    my work environment: aliyun Ubuntu 14.04 64位 first phase:apt-get update    (it is very important,oth ...

  7. Xamarin部署时遇到错误: Failure [INSTALL_FAILED_UPDATE_INCOMPATIBLE]

    1 把adb命令加入到环境变量. ADB 的位置:C:\Users\USER\AppData\Local\Android\android-sdk\platform-tools 2. 卸载包,执行(是a ...

  8. group_concat函数

  9. 山东理工oj--1912--IP地址(水题)

     IP地址 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 2011年2月3日,国际互联网名称与数字地址分配机构(ICANN) ...

  10. 移动端 input 获取焦点后弹出带enter(类似于搜索,确定,前往)键盘,以及隐藏系统键盘

    一:调出系统带回车键的键盘 在项目中经常有输入框,当输入完成后点击确定执行相应的动作.但是有些设计没有确定或者搜索按钮,这就需要调用系统键盘,点击系统键盘的确定后执行相应动作. 但是单纯的input是 ...