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 ...
随机推荐
- 单片机ISP、IAP和ICP几种烧录方式的区别
单片机ISP.IAP和ICP几种烧录方式的区别 玩单片机的都应该听说过这几个词.一直搞不太清楚他们之间的区别.今天查了资料后总结整理如下. ISP:In System Programing,在系统编程 ...
- 使用SpringBoot实现登录注册的几个问题
一.用户名密码都正确的情况下被登录拦截器拦截 控制台报错:org.apache.ibatis.executor.ExecutorException: A query was run and no Re ...
- 学习java的第二十天
一.今日收获 1.java完全学习手册第三章算法的3.2排序,比较了跟c语言排序上的不同 2.观看哔哩哔哩上的教学视频 二.今日问题 1.快速排序法的运行调试多次 2.哔哩哔哩教学视频的一些术语不太理 ...
- windows Visual Studio 上安装 CUDA【转载】
原文 : http://blog.csdn.net/augusdi/article/details/12527497 前提安装: Visual Studio 2012 Visual Assist X ...
- show processlist命令详解
1.show processlist; SHOW PROCESSLIST显示哪些线程正在运行.您也可以使用mysqladmin processlist语句得到此信息.如果您有SUPER权限,您可以看到 ...
- Linux基础命令---get获取ftp文件
get 使用lftp登录ftp服务器之后,可以使用get指令从服务器获取文件. 1.语法 get [-E] [-a] [-c] [-O base] rfile [-o lfil ...
- UIImageView总结
UIImageView UIKit框架提供了非常多的UI控件,但并不是每一个都很常用,有些控件可能1年内都用不上,有些控件天天用,比如UIButton.UILabel.UIImageView.UITa ...
- 【面试】【Linux】【Web】基础概念
1. HTTP https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol 2. TCP handshake https://en.wikipe ...
- 2、Spring的IOC标签介绍以及实例
一.Spring_ioc配置文件bean标签介绍 1. bean标签 名称:bean 类型:标签 归属:beans标签 作用:定义spring中的资源,受此标签定义的资源将受到spring控制 格式: ...
- 【.NET 与树莓派】控制彩色灯带(WS28XX)
彩色灯带,相信不用老周多说,大家都知道,没准你家里的灯墙里面就有.老周的茅屋是早期建造的,所以没有预留的灯槽,明灯的话是不好看的,因此老周家里没使用灯带.不过,像柜子后面,显示器后面,书桌边沿这些地方 ...