Fang Fang

Time Limit: 1 Sec

Memory Limit: 256 MB

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=5455

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

8
ffcfffcffcff
cffcfff
cffcff
cffcf
ffffcffcfff
cffcfffcffffcfffff
cff
cffc

Sample Output

Case #1: 3
Case #2: 2
Case #3: 2
Case #4: -1
Case #5: 2
Case #6: 4
Case #7: 1
Case #8: -1

HINT

题意

f1 = f,f2 = ff, f3 = cff ,fn = fn-1+fn-2

给你一个字符串,问你最少有多少个f里面的东西组成

题解:

坑题,很简单的贪心,把c扔在前面就好

坑点:他可能输入不只是c,f,有可能输入乱七八糟的东西= =

比如caa

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 2000000 + 500
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
//************************************************************************************** string s;
int main()
{
int t;scanf("%d",&t);
for(int cas = ;cas<=t;cas++)
{
cin>>s;
int flag = ;
int st = ;
int len = s.size(); for(int i=;i<len;i++)
if(s[i]!='c'&&s[i]!='f')
flag=;
if(flag==)
{
printf("Case #%d: -1\n",cas);
continue;
}
for(int i=;i<len;i++)
if(s[i]=='c')
{
flag = ;
st = i;
break;
} if(!flag)
{
int ans = len/;
if(len%==)ans++;
printf("Case #%d: %d\n",cas,ans);
continue;
}
int ans = ;
flag = ;
int temp = ;
temp = ;
for(int i=st;i<(st+len);i++)
{
if(s[i%len]=='c')
{
if(temp<)
flag = ;
temp = ;
ans++;
}
else
temp++;
}
if(temp<)
flag = ;
if(flag)
printf("Case #%d: -1\n",cas);
else
printf("Case #%d: %d\n",cas,ans);
}
}

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. Fang Fang HDU - 5455 (思维题)

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

  3. HDU - 5455 Fang Fang

    Problem Description Fang Fang says she wants to be remembered.I promise her. We define the sequence  ...

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

  5. hdu 5459(递推好题)

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

  6. FZU- Problem 1147 Tiling,递推坑题,大数水过~~

    Problem 1147 Tiling Time Limit: 1000 mSec Memory Limit : 32768 KB http://acm.fzu.edu.cn/problem.php? ...

  7. 【BZOJ-1952】城市规划 [坑题] 仙人掌DP + 最大点权独立集(改)

    1952: [Sdoi2010]城市规划 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 73  Solved: 23[Submit][Status][ ...

  8. hdu 5455(字符串处理)

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

  9. String类面试坑题

    1.面试坑题F:\SHJT\JavaWorkspace\JavaSE\workspace\day13ezra\src\cn\itcast\sh\classcode\BTStringLastIndexO ...

随机推荐

  1. Hibernate个人总结

    编写Hibernate第一个程序 Hibernate是目前最流行的持久层框架,专注于数据库操作.使用Hibernate框架能够使开发人员从繁琐的SQL语句和复杂的JDBC中解脱出来.Hibernate ...

  2. s​e​t​ ​x​a​c​t​_​a​b​o​r​t ​用​法

    默认行为 默认为SET XACT_ABORT OFF,没有事务行为. SET XACT_ABORT ON SET XACT_ABORT ON分为两种: 1.总体作为一个事务,整体提交或整体回滚,格式为 ...

  3. 几种通讯协议的比较RMI > Httpinvoker >= Hessian >> Burlap >> web service

    一.综述本文比较了RMI,Hessian,Burlap,Httpinvoker,web service等5种通讯协议的在不同的数据结构和不同数据量时的传输性能.RMI是java语言本身提供的远程通讯协 ...

  4. Ext入门学习系列(四)面板控件

    第四章 使用面板 上节学习了Ext复杂对话框,更进一步了解了Ext的运行机制.本章重点来了解Ext所有控件的基础——面板控件. 一.Ext的面板是什么? 同样先来看看几个效果: 基本面板,点击右上角小 ...

  5. MySQL 存储过程删除大表

    1.权限问题 alter routine 编辑或删除存储过程 create routine 建立存储过程 execute 创建存储过程 2.存储过程相关的一些命令 show procedure sta ...

  6. Hbase学习笔记(安装和基础知识及操作)

    1.Hbase简介 1.面向列的分布式数据库 2. 以HDFS作为文件系统 3. 利用MapReduce处理Hbase中海量数据 4. ZookKeeper作为协调工具 5. sqoop提供Hbase ...

  7. SoapUI入门

    注:需要使用发布的webService接口 我们一般用的是impl接口调用,不大用得上soapUI.看到一份简历上写了使用soapUI做webService测试,想了解一下什么是soapUI soap ...

  8. 不要62(HDU 2089数位dp入门)

    题意:统计区间 [a,b] 中不含 4 和 62 的数字有多少个. 分析:dp[i][f]数字表示不含 4 和 62的前提下,剩余长度为 len ,首位是否为 6 的个数. #include < ...

  9. CodeForce---Educational Codeforces Round 3 The best Gift 解题报告

    对于这题笔者认为可以用数学排列来算,但是由于笔者很懒所以抄了一段大神的代码来交个大家了, 这位大神的基本想法就是通过记录各类书的数量,再暴力破解: 下面贴出这位大神的代码吧: #include< ...

  10. 动态代理CGlib实例

    1.委托类: package 动态代理2; //需要对这个类进行增强 public class UserService { public void create() { System.out.prin ...