Fang Fang says she wants to be remembered. 
I promise her. We define the sequence FF of strings. 
F0 = ‘‘f",F0 = ‘‘f", 
F1 = ‘‘ff",F1 = ‘‘ff", 
F2 = ‘‘cff",F2 = ‘‘cff", 
Fn = Fn−1 + ‘‘f", for n > 2Fn = Fn−1 + ‘‘f", for n > 2 
Write down a serenade as a lowercase string SS in a circle, in a loop that never ends. 
Spell the serenade using the minimum number of strings in FF, or nothing could be done but put her away in cold wilderness.

InputAn positive integer TT, indicating there are TT test cases. 
Following are TT lines, each line contains an string SS as introduced above. 
The total length of strings for all test cases would not be larger than 106106.OutputThe output contains exactly TT lines. 
For each test case, if one can not spell the serenade by using the strings in FF, output −1−1. Otherwise, output the minimum number of strings in FF to split SSaccording 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

Shift the string in the first test case, we will get the string "cffffcfffcff"
and it can be split into "cffff", "cfff" and "cff". 题意很简单不说了。
题解:sumf记录f的个数,然后遇见一个c判断一下是不是符合题意,如果‘c’在[0,len-1)区间内,判断一下它的下一个以及下下个是不是f,因为这个字符串是循环串,所以如果这个c是倒数第二个,判断一下最后一个和第一个字符是不是f
如果最后一个字符是c,判断一下第一个和第二个字符是不是f,如果是,sumc++; 不存在的时候就是sumf+sumc!=字符串的长度就行了

 代码如下:

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
int T,t=;
scanf("%d",&T);
while(T--)
{
string a;
cin>>a; int len=a.length();
int sumc=,sumf=,flag=;
for(int i = ;i < len;i++)
{
if(a[i]=='f')
sumf++;
else if(a[i]=='c')
{
if(a[i+]=='f'&&a[i+]=='f')
sumc++;
if(i==len-)
{
if(a[i+]=='f'&&a[]=='f')
sumc++;
}
if(i==len-)
{
if(a[]=='f'&&a[]=='f')
sumc++;
}
}
}
printf("Case #%d: ",t++);
if(sumc+sumf!=len)
printf("-1\n");
else
{
if(sumc==)
printf("%d\n",sumf+>>);
else
printf("%d\n",sumc);
}
}
return ;
}

Fang Fang HDU - 5455 (思维题)的更多相关文章

  1. hdu 4883 思维题

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=4883 TIANKENG’s restaurant Time Limit: 2000/1000 MS (Ja ...

  2. hdu 5014 思维题/推理

    http://acm.hdu.edu.cn/showproblem.php?pid=5014 从小数開始模拟找方法规律,然后推广,尤其敢猜敢尝试,错了一种思路继续猜-----这是一种非常重要的方法啊 ...

  3. Just Random HDU - 4790 思维题(打表找规律)分段求解

    Coach Pang and Uncle Yang both love numbers. Every morning they play a game with number together. In ...

  4. HDU 6464 权值线段树 && HDU 6468 思维题

    免费送气球 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...

  5. 朋友HDU - 5963 (思维题) 三种方法

    传送门 题目描述 输入 输出 样例输入 Sample Input 样例输出 Boys win! Girls win! Girls win! Boys win! Girls win! Boys win! ...

  6. hdu 5455 Fang Fang 坑题

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

  7. HDU - 5455 Fang Fang

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

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

  9. HDU 5455:Fang Fang 查cff个数

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

随机推荐

  1. 数据库数据在Java占用内存简单估算

    数据库数据在Java占用内存简单估算 结论: 1.数据库记录放在JAVA里,用对象(ORM一般的处理方式)须要4倍左右的内存空间.用HashMap这样的KV保存须要10倍空间; 2.假设你主要数据是t ...

  2. LeetCode 939. Minimum Area Rectangle (最小面积矩形)

    题目标签:HashMap 题目给了我们一组 xy 上的点坐标,让我们找出 能组成矩形里最小面积的那个. 首先遍历所有的点,把x 坐标当作key 存入map, 把重复的y坐标 组成set,当作value ...

  3. 一次次迭代 百度语音生成 api 字幕 语音的同步性 关键

    发音字符 数一样 D:\myv\semHAND9myuid1523961381.avi 0.7053863117786668 --------------- 深圳市雅超服饰有限公司是一家专业设计制作高 ...

  4. Ip获取请求ip

    public class IPAdress { public static bool isIP(string str1) { || str1.Length > ) return false; s ...

  5. 快速访问GitHub

    Github网站可以访问,但是由于网络代理商的原因,造成访问速度很慢. 本文采取方法:手动更改hosts Hosts是一个没有扩展名的系统文件,可以用记事本等工具打开,其作用就是将一些常用的网址域名与 ...

  6. Access restriction:The type JPEGCodec is not accessible due to restriction on required library C:\Program Files\Java\jre6\lib\rt.jar 报错

    报错: Access restriction:The type JPEGCodec is not accessible due to restriction on required library C ...

  7. Parlay Wagering

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2833 题意:讲述了一种投小钱赢大钱的赌博方式, ...

  8. 一个thinkphhp的聊天类,感觉还可以

    <?phpnamespace Common\Controller;use Think\Controller;class HxController extends Controller{ /** ...

  9. [Swift通天遁地]四、网络和线程-(10)处理图片:压缩、缩放、圆角、CoreImage滤镜、缓存

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  10. zookeeper集群安装及使用详解

    1. Zookeeper简介 ZooKeeper是一个开源的分布式框架,提供了协调分布式应用的基本服务.它向外部应用暴露一组通用服务——分布式同步(Distributed Synchronizatio ...