Fibonacci String(hdu 1708)
Fibonacci String
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5008 Accepted Submission(s): 1690
Now he is thinking about a new thing -- Fibonacci String .
He defines : str[n] = str[n-1] + str[n-2] ( n > 1 )
He is so crazying that if someone gives him two strings str[0] and str[1], he will calculate the str[2],str[3],str[4] , str[5]....
For example :
If str[0] = "ab"; str[1] = "bc";
he will get the result , str[2]="abbc", str[3]="bcabbc" , str[4]="abbcbcabbc" …………;
As the string is too long ,Jim can't write down all the strings in paper. So he just want to know how many times each letter appears in Kth Fibonacci String . Can you help him ?
Then N cases follow.
In each case,there are two strings str[0], str[1] and a integer K (0 <= K < 50) which are separated by a blank.
The string in the input will only contains less than 30 low-case letters.
If you still have some questions, look the sample output carefully.
Please output a blank line after each test case.
To make the problem easier, you can assume the result will in the range of int.
1 #include<iostream>
2 #include<string.h>
3 #include<queue>
4 #include<stdio.h>
5 #include<algorithm>
6 using namespace std;
7 char a[40];
8 char b[40];
9 int aa[26];
10 int bb[26];
11 int cc[26];
12 int main(void)
13 {
14 int n,i,j,k,p,q;
15 scanf("%d",&k);
16 while(k--)
17 {
18 scanf("%s %s",a,b);
19 memset(aa,0,sizeof(aa));
20 memset(bb,0,sizeof(bb));
21 scanf("%d",&p);
22 int l=strlen(a);
23 int r=strlen(b);
24 for(i=0;i<l;i++)
25 {aa[a[i]-'a']+=1;
26 }
27
28 for(i=0;i<r;i++)
29 {
30 bb[b[i]-'a']+=1;
31 }
32 if(p==0)
33 {
34 for(i=0;i<=25;i++)
35 {
36 printf("%c:",i+'a');
37 printf("%d\n",aa[i]);
38 }
39 }
40 else if(p==1)
41 {
42 for(i=0;i<=25;i++)
43 {
44 printf("%c:",i+'a');
45 printf("%d\n",bb[i]);
46 }
47 }
48 else
49 {
50 for(i=0;i<p-1;i++)
51 {
52 for(j=0;j<=25;j++)
53 {
54 cc[j]=aa[j]+bb[j];
55 }
56 for(j=0;j<=25;j++)
57 {
58 aa[j]=bb[j];
59 }
60 for(j=0;j<=25;j++)
61 {
62 bb[j]=cc[j];
63 }
64 }
65 for(i=0;i<=25;i++)
66 {
67 printf("%c:",i+'a');
68 printf("%d\n",cc[i]);
69 }
70 }printf("\n");
71
72 }
73 return 0;
74 }
Fibonacci String(hdu 1708)的更多相关文章
- HDU 1708 简单dp问题 Fibonacci String
Fibonacci String Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 1708 Fibonacci String
Fibonacci String Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- HDOJ(HDU) 1708 Fibonacci String
Problem Description After little Jim learned Fibonacci Number in the class , he was very interest in ...
- String HDU 5672(双指针)
String HDU 5672(双指针) 传送门 题意:一个字符串中找到所有拥有不少于k个不同的字符的子串. import java.io.*; import java.util.*; public ...
- Combine String HDU - 5707 dp or 广搜
Combine String HDU - 5707 题目大意:给你三个串a,b,c,问a和b是不是恰好能组成c,也就是a,b是不是c的两个互补的子序列. 根据题意就可以知道对于c的第一个就应该是a第一 ...
- (KMP)Count the string -- hdu -- 3336
http://acm.hdu.edu.cn/showproblem.php?pid=3336 Count the string Time Limit: 2000/1000 MS (Java/Other ...
- (字符串) Hidden String -- HDU -- 5311
链接: http://acm.hdu.edu.cn/showproblem.php?pid=5311 Time Limit: 2000/1000 MS (Java/Others) Memory ...
- HDU 1708
思路 :二位数组维护数目. #include<iostream> #include<stdio.h> #include<stdlib.h> #include< ...
- Count the string - HDU 3336(next+dp)
题目大意:给你一个串求出来这个串所有的前缀串并且与前缀串相等的数量,比如: ababa 前缀串{"a", "ab", "aba", &quo ...
随机推荐
- 突破冯·诺依曼架构瓶颈!全球首款存算一体AI芯片诞生
过去70年,计算机一直遵循冯·诺依曼架构设计,运行时数据需要在处理器和内存之间来回传输. 随着时代发展,这一工作模式面临较大挑战:在人工智能等高并发计算场景中,数据来回传输会产生巨大的功耗:目前内存系 ...
- 我可以减肥失败,但我的 Docker 镜像一定要瘦身成功!
作者|徐伟 来源|尔达 Erda 公众号 简介 容器镜像类似于虚拟机镜像,封装了程序的运行环境,保证了运行环境的一致性,使得我们可以一次创建任意场景部署运行.镜像构建的方式有两种,一种是通过 do ...
- Spark(一)【spark-3.0安装和入门】
目录 一.Windows安装 1.安装 2.使用 二.Linux安装 Local模式 1.安装 2.使用 yarn模式 1.安装 2.使用 3.spark的历史服务器集成yarn 一.Windows安 ...
- Yarn【架构、原理、多队列配置】
目录 一.什么是yarn 二.yarn的基本架构和角色 三.yarn的工作机制 四.任务提交流程 五.资源调度器 FIFO 容量调度器 公平调度器 六.容量调度器多队列提交案例实操 1.案例:配置de ...
- C语言产生随机数(伪)
C语言的获取随机数的函数为rand(), 可以获得一个非负整数的随机数.要调用rand需要引用头文件stdlib.h.要让随机数限定在一个范围,可以采用模除加加法的方式.要产生随机数r, 其范围为 m ...
- 编程之美Q1
题目 和数书页有点类似,就直接数吧 #include<iostream> using namespace std; class q1 { public: size_t func(size_ ...
- 使用Rapidxml重建xml树
需求 : 重建一棵xml树, 在重建过程中对原来的标签进行一定的修改. 具体修改部分就不给出了, 这里只提供重建部分的代码 code : /****************************** ...
- 规范——Java后端开发规范
Java后端开发规范 一.技术栈规约 二.命名规范 三.Java代码规范(注释规范.异常与日志.代码逻辑规范) 四.Mybatis与SQL规范 五.结果检查(单元测试及代码扫描) 六.安全规范 一.技 ...
- SpringBoot让测试类飞起来的方法
单元测试是项目开发中必不可少的一环,在 SpringBoot 的项目中,我们用 @SpringBootTest 注解来标注一个测试类,在测试类中注入这个接口的实现类之后对每个方法进行单独测试. 比如下 ...
- ORACLE CACHE BUFFER CHAINS原理
原理图如下: 一个cache buffer chains 管理多个hash bucket,受隐含参数:_db_block_hash_buckets(控制管理几个hash bucket)