【题目链接】: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. 洛谷1099 [NOIP2007] 树网的核

    链接https://www.luogu.org/problemnew/show/P1099 题目描述 设T=(V,E,W)是一个无圈且连通的无向图(也称为无根树),每条边到有正整数的权,我们称TTT为 ...

  2. VUE:事件处理和表单输入绑定

    事件处理 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <titl ...

  3. [terry笔记]文件操作

    如下记录一次作业: 很显然,我这个应该属于二逼青年版,会在以后更新文艺青年版的答案. 1.模仿sed,一个文件中,用新字符串替换老字符串. # file = input("file_name ...

  4. UVALive 2664 One-way traffic

    One-way traffic Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVALive. Or ...

  5. IntegerToBinaryString

    IntegerToBinaryString 方法写的非常的巧妙:佩服佩服! package com.stono.jdk; public class IntegerToBinaryString { pu ...

  6. xpee.vbs

    xpee.vbs Win 8安装之后每一次重启桌面都会有一个360浏览器的快捷方式,终于找到原因了, 在Windows/System下面有这么个文件: Set ws = CreateObject(&q ...

  7. CURL库的宏定义列表

    列表CURL库一共同拥有17个函数 curl_close:关闭CURL会话 curl_copy_handle:复制一个CURL会话句柄,同一时候3复制其全部參数 curl_errno:返回最后一个错误 ...

  8. [Gatsby] Install Gatsby and Scaffold a Blog

    In this lesson, you’ll install Gatsby and the plugins that give the default starter the ability to t ...

  9. Math类概述及其成员方法

    Math 类包括用于运行基本数学运算的方法,如初等指数.对数.平方根和三角函数,这个类寻常开发中用的不多,可是在某些需求上会用到,比方求二个用户年龄的相差多少岁,这会用到Math类中的方法!如今把Ma ...

  10. SQL Server: Windows Firewall with Advanced Security

    SQL Database Engine: TCP 1433 & UDP 1434 SQL Analysis Service: TCP 2383 (2382 if named instance) ...