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 ...
随机推荐
- nordic 51822 sdk. timer 的使用
它的源代码和头文件分别为app_timer.c/app_timer.h.这是Nordic为我们提供的虚拟定时器,这个定时器不同于硬件上的TIMER,而是基于RTC1实现的一种虚拟定时器,其将定时功能作 ...
- LeetCode:旋转图像
题目描述 给定一个 n × n 的二维矩阵 matrix 表示一个图像.请你将图像顺时针旋转 90 度. 你必须在 原地 旋转图像,这意味着你需要直接修改输入的二维矩阵.请不要 使用另一个矩阵来旋转图 ...
- Windows cmd 命令行基本操作
Windows cmd 命令行基本操作 1. 进入到指定根目录 注意:不区分大小写 例如进入到 D 盘 2. 进入到指定的目录 例如 (如果目录文件名太长,可以使用 tab 键来自动补全.重复按可以进 ...
- A Child's History of England.22
CHAPTER 8 ENGLAND UNDER WILLIAM THE FIRST, THE NORMAN CONQUEROR Upon the ground where the brave Haro ...
- Flink(六)【ParameterTool类】
ParameterTool 工具类 object ParameterToolTest { def main(args: Array[String]): Unit = { val params: Par ...
- Spark(十七)【SparkStreaming需求练习】
目录 一.环境准备 1.pom文件 2.bean 3.工具类 JDBCUtils Properties工具类 3.创建BaseApp 需求一:动态添加黑名单 需求二:广告点击量实时统计 需求三:最近一 ...
- JTable 单元格合并 【转】
单元格合并 一.单元格合并.(1)我们可以使用Jtable的三个方法:getCellRect(),columnAtPoint(),and rowAtPoint().第一个方法返回一个单元格的边界(Re ...
- node环境变量配置
1.Node.js 官方网站下载:https://nodejs.org/en/ 2.打开安装,傻瓜式下一步即可,然后配置环境变量 3.因为在执行例如npm install webpack -g等命令全 ...
- 编译安装haproxy2.0
先解决lua环境,(因为centos自带的版本不符合haproxy要求的最低版本(5.3)先安装Lua依赖的包 [root@slave-master lua-5.3.5]# yum install ...
- mysql读写分离(proxySQL) lamp+proxysql+nfs
先在主从节点安装mysql [root@master-mariadb ~]# yum install mariadb-server -y [root@slave-mariadb ~]# yum ins ...