【codeforces 379D】New Year Letter
【题目链接】: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的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【19.77%】【codeforces 570D】Tree Requests
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【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 ...
- 【codeforces 757A】Gotta Catch Em' All!
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 754B】 Ilya and tic-tac-toe game
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 761C】Dasha and Password(动态规划做法)
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 761C】Dasha and Password(贪心+枚举做法)
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 766C】Mahmoud and a Message
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【75.28%】【codeforces 764B】Decoding
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
随机推荐
- Jquery复习总结
1.选择器: $(".class") $("#id") $("div") $("a p") $(div:first).c ...
- "随笔"列表 - 按时间先后顺序排列
这是一个测试 linux采用scp命令拷贝文件到本地,拷贝本地文件到远程服务器 美化博客园 virtual box虚拟机在linux下设置共享文件夹 纯净版linux (debian)挂载Virtua ...
- 聚类(Clustering)
简介 相对于决策树.朴素贝叶斯.SVM等有监督学习,聚类算法属于无监督学习. 有监督学习通常根据数据集的标签进行分类,而无监督学习中,数据集并没有相应的标签,算法仅根据数据集进行划分. 由于具有出色的 ...
- UGUI图集管理
using UnityEngine; using System.Collections; using System.Collections.Generic; //纹理图集加载管理 public cla ...
- [luogu] P2519 [HAOI2011]problem a (贪心)
P2519 [HAOI2011]problem a 题目描述 一次考试共有n个人参加,第i个人说:"有ai个人分数比我高,bi个人分数比我低."问最少有几个人没有说真话(可能有相同 ...
- 实现双向数据绑定mvvm
实现双向数据绑定mvvm
- OpenRail中地形模型特征的含义
点或点高程 点(附有 X.Y.Z 数据)与任何其他点之间没有功能关系.对开阔地形的随机测量拍摄可以被当做随机点的例子.点图元,如单元.圆圈和文字串是典型的 MICROSTATION 图元,用于用图表定 ...
- Oracle RAC --安装图解
规划:所用linux系统以虚拟化方式安装在esx上,配置有内网的yum源,各分配有16G存储,下面为简单拓扑图 一,下载软件1,地址:http://www.oracle.com/technology/ ...
- httputil用http获取请求的工具类
package com.xiaocan.demo.util; import java.io.IOException; import java.io.InputStream; import java.u ...
- Java8 方法引用与构造器引用,数组引用
package java_8; import org.junit.Test; import java.io.PrintStream; import java.util.Comparator; impo ...