HDU - 5455 Fang Fang
I promise her. We define the sequence F of strings.
F0 = ‘‘f",
F1 = ‘‘ff",
F2 = ‘‘cff",
Fn = Fn−1 + ‘‘f", for n > 2
Write down a serenade as a lowercase string S in a circle, in a loop that never ends.
Spell the serenade using the minimum number of strings in F, or nothing could be done but put her away in cold wilderness.
Following are T lines, each line contains an string S as introduced above.
The total length of strings for all test cases would not be larger than 106.
For each test case, if one can not spell the serenade by using the strings in F, output −1. Otherwise, output the minimum number of strings in F to split S according to aforementioned rules. Repetitive strings should be counted repeatedly.
Sample Input ffcfffcffcff
cffcfff
cffcff
cffcf
ffffcffcfff
cffcfffcffffcfffff
cff
cffc Sample Output
Case #:
Case #:
Case #:
Case #: -
Case #:
Case #:
Case #:
Case #: -
Hint Shift the string in the first test case, we will get the string "cffffcfffcff"
and it can be split into "cffff", "cfff" and "cff".
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5455
**************************************************
题意:f1 = f,f2 = ff, f3 = cff ,fn = fn-1+fn-2,给你一个字符串,问你最少有多少个f里面的东西组成
分析:把前两个直接拼接到最后,然后扫C的位置,看后面是否跟着两个f,注意可能含有其他字母,可能全是f
AC代码:
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<queue>
#include<stdlib.h> using namespace std;
#define N 1010000
#define INF 0x3f3f3f3f char s[N]; int main()
{
int k=,T,i; scanf("%d",&T); while(T--)
{
scanf("%s", s); int f=,ans=;
int len=strlen(s); s[len]=s[];///ffcffc结果是3
s[len+]=s[]; for(i=; i<len; i++)///输入有可能存在其他的字符
{
if(s[i]=='c'||s[i]=='f')
continue ;
else
{
f=;
break;
}
} for(i=;i<len;i++)
{
if(f==)
{
if(s[i]=='c')
{
if(s[i+]=='f'&&s[i+]=='f')
{
i++;
while(i<len&&s[i]=='f')///遇见c跳出
i++;
ans++;///个数加一
i--;
}
else
f=;
}
}
} printf("Case #%d: ",k++);
if(f==)
printf("-1\n");
else if(ans==)///全是f
printf("%d\n", len/+len%);
else
printf("%d\n", ans);
}
return ;
}
HDU - 5455 Fang Fang的更多相关文章
- HDU 5455:Fang Fang 查cff个数
Fang Fang Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total ...
- hdu 5455 Fang Fang 坑题
Fang Fang Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5455 ...
- (字符串处理)Fang Fang -- hdu -- 5455 (2015 ACM/ICPC Asia Regional Shenyang Online)
链接: http://acm.hdu.edu.cn/showproblem.php?pid=5455 Fang Fang Time Limit: 1500/1000 MS (Java/Others) ...
- Fang Fang HDU - 5455 (思维题)
Fang Fang says she wants to be remembered. I promise her. We define the sequence FF of strings. F0 = ...
- hdu 5455(字符串处理)
Fang Fang Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total S ...
- hdu 5455 (2015沈阳网赛 简单题) Fang Fang
题目;http://acm.hdu.edu.cn/showproblem.php?pid=5455 题意就是找出所给字符串有多少个满足题目所给条件的子串,重复的也算,坑点是如果有c,f以外的字符也是不 ...
- HDU 5455 Fang Fang 水题,但题意描述有问题
题目大意:f[1]=f,f[2]=ff,f[3]=ffc,以后f[n]每增加1,字符串增加一个c.给出一个字符串,求最少有多少个f[]组成.(字符串首尾相连,比如:ffcf可看做cfff) 题目思路: ...
- hdu 5459 Jesus Is Here 数学
Jesus Is Here Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...
- hdu 5459(递推好题)
Jesus Is Here Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 65535/102400 K (Java/Others)To ...
随机推荐
- 关于PHPAPI ZEND_API TSRM_API宏的定义
在PHP源码中,我们可以见到诸如PHPAPI ZEND_API TSRM_API等xxx_API(当然还有其他格式的)这样的宏 关于它们的定义都是类似于 #if defined(__GNUC__) & ...
- 非常不错的MySQL优化的8条经验
1.选取最适用的字段属性 MySQL 可以很好的支持大数据量的存取,但是一般说来,数据库中的表越小,在它上面执行的查询也就会越快.因此,在创建表的时候,为了获得更好的性能,我们可以将表中字段的宽度 ...
- 调试技术(/proc、/sys、/dev、strace)
一.在/proc中实现文件 当某个进程读取我们的/proc文件时,内核会分配一个内存页,即PAGE_SIZE字节的内存块.驱动程序可以将数据通过这个内存页返回到用户空间. 第一种方法,不采用seq_f ...
- 一些常见的CFD基本概念(飞机为例)(摘抄)
分享一些常见的,常用的但不容易掌握的CFD基础概念. 1.理想气体:不考虑流体粘性的影响. 2.不可压缩流体/恒密度:不考虑流体密度的变化.
- 分布式版本控制系统Git-----8.fst-forward与no fast foward
当前分支合并到另一分支时,如果没有分歧解决,就会直接移动文件指针.这个过程叫做fastforward. 举例来说,开发一直在master分支进行,但忽然有一个新的想法,于是新建了一个develop的分 ...
- pull类型消息中间件-消息发布者(一)
消息集群架构 对于发送方来说的关键几要素 topic 消息的主题,由用户定义.类似于知乎的话题,Producer发送消息的时候需要指定发送到某一个topic下面,Consumer从某一个topic下面 ...
- Nginx1.8.0版本平滑升级新版本1.9.7
原文:http://www.jb51.net/article/79878.htm 首先查看现在环境nginx的版本为1.8.0 编译的参数只指定了安装路径: 复制代码代码如下: [root@local ...
- mysqldump 数据库备份命令及脚本
mysql -uroot -phowhy@123 -e 'show databases;' | grep -ivE 'waring|database|mysql'|sed -r "s#^(. ...
- [妙味DOM]第三课:Event-事件详解1
知识点总结 焦点事件 onfocus 获取焦点 onblur 失点焦点 obj.focus() 给指定元素设置焦点 obj.blur() 取消指定元素的焦点 obj.select() 选择指定元素里的 ...
- UVa 1354 Mobile Computing | GOJ 1320 不加修饰的天平问题 (例题 7-7)
传送门1(UVa): https://uva.onlinejudge.org/external/13/1354.pdf 传送门2(GOJ): http://acm.gdufe.edu.cn/Probl ...