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 ...
随机推荐
- (转载)java排序实现
Java实现几种常见排序方法 日常操作中常见的排序方法有:冒泡排序.快速排序.选择排序.插入排序.希尔排序,甚至还有基数排序.鸡尾酒排序.桶排序.鸽巢排序.归并排序等. 冒泡排序是一种简单的排序算法. ...
- vc控制台程序关闭事件时的正确处理方式
百度可以找到很多关于这个问题解决的方法 关键控制台API函数:SetConsoleCtrlHandler 在支持C++ 11以上的编译器中,你可以这么做. SetConsoleCtrlHandler( ...
- 非寻常方式学习ApacheTomcat架构及10.0.12源码编译
概述 开启博客分享已近三个月,感谢所有花时间精力和小编一路学习和成长的伙伴们,有你们的支持,我们继续再接再厉 **本人博客网站 **IT小神 www.itxiaoshen.com 定义 Tomcat官 ...
- Docker快速上手入门
Docker 什么是Docker? Docker就是一种虚拟化的技术 可以通过Docker快速的下载使用第三方技术,方便搭建环境 目的:Securely build,share and run any ...
- tomcat在eclipse上发布,Perference下的server找不到解决办法
help--->Install New software得到如下所示 下面work with选项的内容与你的eclipse版本有关 我的eclipse版本为eclipse-java-2019-0 ...
- STM32一些特殊引脚做IO使用的注意事项
1 PC13.PC14.PC15的使用 这三个引脚与RTC复用,<STM32参考手册>中这样描述: PC13 PC14 PC15需要将VBAT与VDD连接,实测采用以下程序驱动4个74HC ...
- Why is the size of an empty class not zero in C++?
Predict the output of the following program? 1 #include<iostream> 2 using namespace std; 3 4 c ...
- ssh 无法使用
ssh 无法运行造成无法远程连接 linux 原因: 我将 /var 目录权限修改成了 777,但 linux 系统出于安全起见,该目录的 7 权限只对 root 用户开放,所以linux 系统认为 ...
- 用Navicat连接数据库-数据库连接(MySQL演示)
用Navicat连接数据库-数据库连接(MySql演示) 已成功连接,连接方式步骤如下: 开始之前首先准备连接信息: [ 一般你可以自己去配置文件中找 或者 问连接过该数据库的人/所有者(负责人/同学 ...
- react18 来了,我 get 到...
大家好! 本文主要是关于即将发布的 react 18 的新特性.那么 react18 带来了什么呢? 详情可以关注 github React 18 工作组仓库 1. automatic batchin ...