Problem Description
Fang Fang says she wants to be remembered.
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.
 
Input
An positive integer T, indicating there are T test cases.
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.
 
Output
The output contains exactly T lines.
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的更多相关文章

  1. HDU 5455:Fang Fang 查cff个数

    Fang Fang Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total ...

  2. hdu 5455 Fang Fang 坑题

    Fang Fang Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5455 ...

  3. (字符串处理)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)  ...

  4. Fang Fang HDU - 5455 (思维题)

    Fang Fang says she wants to be remembered. I promise her. We define the sequence FF of strings. F0 = ...

  5. hdu 5455(字符串处理)

    Fang Fang Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total S ...

  6. hdu 5455 (2015沈阳网赛 简单题) Fang Fang

    题目;http://acm.hdu.edu.cn/showproblem.php?pid=5455 题意就是找出所给字符串有多少个满足题目所给条件的子串,重复的也算,坑点是如果有c,f以外的字符也是不 ...

  7. HDU 5455 Fang Fang 水题,但题意描述有问题

    题目大意:f[1]=f,f[2]=ff,f[3]=ffc,以后f[n]每增加1,字符串增加一个c.给出一个字符串,求最少有多少个f[]组成.(字符串首尾相连,比如:ffcf可看做cfff) 题目思路: ...

  8. hdu 5459 Jesus Is Here 数学

    Jesus Is Here Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...

  9. hdu 5459(递推好题)

    Jesus Is Here Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 65535/102400 K (Java/Others)To ...

随机推荐

  1. Process Explorer(增强任务管理器) V16.05 免费绿色版

    软件名称: Process Explorer(增强任务管理器)软件语言: 中文授权方式: 免费软件运行环境: Win7 / Vista / Win2003 / WinXP 软件大小: 1.2MB图片预 ...

  2. SQLSERVER 的联接查询写法

    1.内连接 语法:[JOIN.INNER JOIN] 作用:两个表相连,加上ON匹配两个表的共同条件. 实例1: SELECT tb_o_i.* FROM tb_o_i INNER JOIN tb_o ...

  3. HDU 2176 取(m堆)石子游戏 尼姆博弈

    题目思路: 对于尼姆博弈我们知道:op=a[1]^a[2]--a[n],若op==0先手必败 一个简单的数学公式:若op=a^b 那么:op^b=a: 对于第i堆a[i],op^a[i]的值代表其余各 ...

  4. css3实现进度条

    HTML 结构很简单,但不是 Single Element: <div class="spinner"><i></i></div> ...

  5. easyUI的treegrid列表添加查询

    一些数据使用treegrid显示,添加筛选条件, 首先创建treegrid列表 var tree = $("#TreeGrid").treegrid({ url:"cha ...

  6. 关于c语言变量的内存分布测试程序

    #include <stdio.h> #include <stdlib.h> ; // 常全局变量 ; // 初始化全局变量 int uninit_global; // 未初始 ...

  7. maven创建spring项目之后,启动报错java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoade

    错误: org.apache.catalina.core.StandardContext listenerStart严重: Error configuring application listener ...

  8. mpich2 下运行时出现“由于目标计算机积极拒绝,无法连接”的错误

    进行mpi并行编程时候,win8下使用mpich2时候,安装目录下找到wmpiexec.exe程序打开,填入编写好的.exe程序地址并制定执行的任务数目的想要运行时候,出现错误: unable to  ...

  9. JAVA的字符编码及问题

    web开发时,字符编码及有时候也会是一个麻烦的问题,没有经验的话,肯定不知道怎么解决,有一定的经验的话,那还是比较简单的.以下,是我学习过程中总结出来的几种字符编码级问题和其解决的方法 1.文档乱码, ...

  10. Bounce 弹飞绵羊

    Bounce 弹飞绵羊 题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2002 分块 将整个大区间分成若干块,每个点维护到下一个块需要跳的次 ...