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. 微信小程序 textarea 简易解决方案

    微信小程序中textarea没有bindchange事件,所以无法在输入时给变量赋值. 虽然可以使用bindblur事件,但是绑定bindblur事件,如果再点击按钮,则先执行完按钮事件后,再去执行b ...

  2. Python基础(六)-内置函数

      map().filter().reduce() map(func,iterator) --> filter(func,iterator) --> reduce(func,iterato ...

  3. 从安装.net Core 到helloWord(Mac上)

    最近听说微软 正式发不了.netCore 1.0 于是就安装了 并安装了vs Code 用于编写一些.net程序 一. .netCore的安装: 首先需要通过brew安装openssl(相信homeB ...

  4. jdbc_servlet基础增删改分页2(userinfo表的)

    1.创建如下文件目录 2.导入MyBatis的jar文件 3.创建实体类 package com.entity; public class Userinfo { private Integer uid ...

  5. 《精通CSS》——个人总结

    [属性选择器] 属性选择器可以根据某个属性是否存在或属性的值来寻找元素. 只有在规定了 !DOCTYPE 时,IE7 和 IE8 才支持属性选择器.在 IE6 及更低的版本中,不支持属性选择. 事例: ...

  6. java 守护线程

    守护线程生命周期: 守护线程是运行在后台的一种特殊线程, 它独立于控制终端并且周期性地执行某种任务或者等待处理某些发生的事件. 也就是说守护线程不依赖于终端,但是依赖于系统,与系统“同生共死”. 当J ...

  7. BOS物流管理系统-第八天

    BOS物流管理系统-第八天-权限系统设计-Shiro 回顾: 两大块业务:基础设置模块,业务派单模块. 两天:权限控制. 拦截器大的范围的.纯登录级别(认证级别)大颗粒的权限控制的一种技术. Shir ...

  8. ZUFE OJ 2145 05机关图

    Description Ink最近得到了一张藏宝图,这张图上共有n个藏宝室,但因为年代久远藏宝图上的路已经模糊不清,于是Ink找到了智慧的Pseudo,Pseudo告诉Ink,这个宝藏中每两个藏宝室之 ...

  9. Partial Tree

    Partial Tree 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5534 完全背包 做这题前去学习了下完全背包,觉得这个优化简直神技!(以前都是 ...

  10. 实验吧Web-FALSE

    笔记: PHP函数isset(): 检测变量是否设置 只能用于变量,传递任何其它参数都将造成解析错误.若想检测常量是否已设置,可使用 defined() 函数 格式:  isset ( mixed v ...