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 Fto 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

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 char s[100006];
 6 int main()
 7 {
 8    int t,i,ans,j,flag,k=1,a;
 9    scanf("%d",&t);
10    getchar();
11    while (t--)
12    {
13       flag=0;
14       gets(s);
15       if (s[0]==' ')
16       {
17          printf("Case #%d: ",k);
18          k++;
19          printf("0\n");
20          continue;
21       }
22       for (i=0;s[i];i++){
23       if (s[i]!='c'&&s[i]!='f') {flag=1;break;}
24       if (s[i]=='c') break;
25       }
26       if (s[i]=='\0')
27       {
28          printf("Case #%d: ",k);
29          k++;
30          printf("%d\n",i/2+i%2);
31          continue;
32       }
33       a=i;
34       ans=1;
35       j=0;
36       for (i=i+1;s[i];i++)
37       {
38          if (s[i]!='c'&&s[i]!='f') {flag=1;break;}
39          if (s[i]!='c') j++;
40          else
41          {
42             if (j>=2)
43             {
44                j=0;
45                ans++;
46             }
47             else
48             {
49                flag=1;
50                break;
51             }
52          }
53       }
54       if (j+a<2) flag=1;
55       printf("Case #%d: ",k);
56       if (flag) printf("-1\n");
57       else printf("%d\n",ans);
58       k++;
59    }
60 }

转载于:https://www.cnblogs.com/pblr/p/4822000.html

hdu 5455 Fang Fang相关推荐

  1. 【HDU - 5455】Fang Fang(水题,有坑)

    题干: Fang Fang says she wants to be remembered.  I promise her. We define the sequence FF of strings. ...

  2. HDU-5455 Fang Fang (思维)

    题目链接 题目:输入一个字符串,问最少能由几个Fi组成,若不能恰好由Fi组成,输出-1: 这题有一个坑点就是如果输入的字符串中有除c和f以外的其他字符时直接输出-1(刚开始做的时候没有想到这一点,被坑 ...

  3. 【 HDU - 5459】Jesus Is Here(dp)

    题干: I've sent Fang Fang around 201314 text messages in almost 5 years. Why can't she make sense of w ...

  4. 2015 ACM/ICPC Asia Regional Shenyang Online题解

    以下所有AC题解程序来自"仙客传奇"团队. AC题数:7/13 ABCFGJL A. Traversal AC的C++语言程序: #include <bits/stdc++. ...

  5. 递推DP HDOJ 5459 Jesus Is Here

    题目传送门 题意:简单来说就是sn = sn-1 + sn-2递推而来,求其中所有c字符的:∑i<j:sn[i..i+2]=sn[j..j+2]=''cff"(j−i) mod 530 ...

  6. 开启注册 | AAAI 2022论文北京预讲会,21场报告+24个Poster等你来

    注册官网:https://event.baai.ac.cn/activities/228 国际人工智能会议AAAI 2022论文北京预讲会由中国中文信息学会青年工作委员会主办.智源社区和北京航空航天大 ...

  7. 蓝桥杯——机器人行走

    某少年宫引进了一批机器人小车.可以接受预先输入的指令,按指令行动.小车的基本动作很简单,只有3种:左转(记为L),右转(记为R),向前走若干厘米(直接记数字). 例如,我们可以对小车输入如下的指令:1 ...

  8. 王伟storm_王伟 - 南京大学 - 化学化工学院

    个人简介 2004年和2009年分别从中国科学技术大学化学系获得理学学士和分析化学博士学位.2009-2013在美国亚利桑那州立大学从事博士后研究.2013年12月起任南京大学教授.2017年获得中国 ...

  9. PHP下拉框选择的实现方法

    实现 第一种PHP下拉框实现方法: < ?php //提交下拉框; //直接饱触发onchange事件的结果 $id=$_GET['myselect']; // myselect 为locati ...

  10. 基于java的学生信息管理系统(含源文件)

    欢迎添加微信互相交流学习哦! 项目源码:https://gitee.com/oklongmm/biye 内容摘要    - 2 - 引言    - 4 - 学生信息管理系统开发的意义和目的    - ...

最新文章

  1. linux 设备事件管理服务 systemd-udevd.service 简介
  2. 在一个字符串中找到第一个只出现一次的字符
  3. mysql多客户端数据不同步_一种多终端设备上的数据同步方法
  4. 太省事了!高分SCI全套优质模板下载
  5. kmp学英语必须设置
  6. pytorch查看loss曲线_pytorch loss总结与测试
  7. 使用RegistryKey的一个注意点
  8. 2021年中国磁感应芯片市场趋势报告、技术动态创新及2027年市场预测
  9. 你知道吗?世界上绝美神奇的25条路
  10. forward(转发)与redirect(重定向)的区别
  11. Viddy排名App Store免费应用第二,力压InstagramDraw Sth
  12. 全局函数声明和静态函数声明
  13. 搭建centos 7 并部署ftp的详细过程
  14. 【HarmonyOS】鸿蒙3.0使用WebView进行链接跳转,告警“hwbr_engine_AwContentsClient: Denied starting an intent without a
  15. Adversarial Semantic Alignment for Improved Image Captions
  16. Zookeeper集群启动异常: Cannot open channel to x at election address xx/xxx.xxx.xxx.xxx:3888
  17. python发送文件_Python发送邮件(最全)
  18. 固件和微码到底啥区别
  19. 黑马培训有python吗
  20. 最全汉字正则校验:只允许汉字,允许带点,允许拓展汉字,生僻字,比如䶮之类的汉字

热门文章

  1. pocket英语语法入门
  2. 元转万元单位换算_excel数值单位转换-----元与万元、千元、百元的转换
  3. 按键精灵打怪学习-多线程后台坐标识别
  4. 计算机测绘程序设计实验报告,计算机测绘程序及设计实验报告.doc
  5. vue 对象提供的属性功能、通过axio请求数据(2)
  6. 大数据给人们生活带来的改变_大数据给我们的生活带来了哪些改变?
  7. USB总线-Linux内核USB3.0控制器初始化代码分析(三)
  8. Chrome浏览器打开微信页面
  9. Cocos2d-x 3.x基础学习: 拖尾渐隐效果MotionStreak
  10. mysql 表空间碎片_MySQL碎片产生的原因及清除表空间碎片的方法