链接:

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

Fang Fang

Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 233    Accepted Submission(s): 110

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
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".

代码:

#include <iostream>
#include <stdio.h>
#include <string.h> using namespace std; #define N 1100000
char s[N]; int main()
{
int t, iCase=;
scanf("%d", &t); while(t--)
{
int i, num=, sum=, flag=, len; scanf("%s", s); len = strlen(s)-; for(i=; i<=len; i++)
{
if(s[i]=='f')
num++;
if(s[i]!='f' && s[i]!='c')
flag = ;
if(s[i]=='c')
{
if(i==len- && s[]=='f' && s[len]=='f')
sum ++;
else if(i==len && s[]=='f' && s[]=='f')
sum ++;
else if(s[i+]=='f' && s[i+]=='f')
sum++;
else
flag = ;
}
} printf("Case #%d: ", iCase++); if(flag)
printf("-1\n");
else
{
if(sum)
printf("%d\n", sum);
else if(len+==num)
printf("%d\n", (num+)/);
else
printf("-1\n");
}
}
return ;
}

(字符串处理)Fang Fang -- hdu -- 5455 (2015 ACM/ICPC Asia Regional Shenyang Online)的更多相关文章

  1. 2015 ACM/ICPC Asia Regional Shenyang Online

    1001 Traversal 1002 Best Solver 1003 Minimum Cut 类似于POJ 3417的做法. 考虑每条新边对树边的覆盖次数. 每条树边被覆盖的次数其实就是断裂这条树 ...

  2. HDU 5458 Stability(双连通分量+LCA+并查集+树状数组)(2015 ACM/ICPC Asia Regional Shenyang Online)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5458 Problem Description Given an undirected connecte ...

  3. Hdu 5451 Best Solver (2015 ACM/ICPC Asia Regional Shenyang Online) 暴力找循环节 + 递推

    题目链接: Hdu  5451  Best Solver 题目描述: 对于,给出x和mod,求y向下取整后取余mod的值为多少? 解题思路: x的取值为[1, 232],看到这个指数,我的心情是异常崩 ...

  4. Hdu 5459 Jesus Is Here (2015 ACM/ICPC Asia Regional Shenyang Online) 递推

    题目链接: Hdu 5459 Jesus Is Here 题目描述: s1 = 'c', s2 = 'ff', s3 = s1 + s2; 问sn里面所有的字符c的距离是多少? 解题思路: 直觉告诉我 ...

  5. Hdu 5452 Minimum Cut (2015 ACM/ICPC Asia Regional Shenyang Online) dfs + LCA

    题目链接: Hdu 5452 Minimum Cut 题目描述: 有一棵生成树,有n个点,给出m-n+1条边,截断一条生成树上的边后,再截断至少多少条边才能使图不连通, 问截断总边数? 解题思路: 因 ...

  6. hdu 6197 2017 ACM/ICPC Asia Regional Shenyang Online array array array【最长不上升子序列和最长不下降子序列】

    hdu 6197 题意:给定一个数组,问删掉k个字符后数组是否能不减或者不增,满足要求则是magic array,否则不是. 题解:队友想的思路,感觉非常棒!既然删掉k个后不增或者不减,那么就先求数组 ...

  7. HDU 6198(2017 ACM/ICPC Asia Regional Shenyang Online)

    思路:找规律发现这个数是斐波那契第2*k+3项-1,数据较大矩阵快速幂搞定.   快速幂入门第一题QAQ #include <stdio.h> #include <stdlib.h& ...

  8. (并查集)Travel -- hdu -- 5441(2015 ACM/ICPC Asia Regional Changchun Online )

    http://acm.hdu.edu.cn/showproblem.php?pid=5441 Travel Time Limit: 1500/1000 MS (Java/Others)    Memo ...

  9. (二叉树)Elven Postman -- HDU -- 54444(2015 ACM/ICPC Asia Regional Changchun Online)

    http://acm.hdu.edu.cn/showproblem.php?pid=5444 Elven Postman Time Limit: 1500/1000 MS (Java/Others)  ...

随机推荐

  1. python-股票数据定向爬取

    re.findall soup.find_all ---------Q---- for i in ***: ***可以是什么类型,主要是关心什么类型的不可以 ------------trackback ...

  2. 流和Variant的转换

    procedure TForm2.VariantToStream (const v : olevariant;                                   Stream : T ...

  3. orientdb 学习

    简介 OrientDB 是一款 NoSQL 数据库.是一种文档-图数据库.即:既具有文档数据库的特性,又具有图数据库的功能. 端口 2424  OrientDB 监听 二进制 访问的的端口 (即:通过 ...

  4. java mysql大数据量批量插入与流式读取分析

    总结下这周帮助客户解决报表生成操作的mysql 驱动的使用上的一些问题,与解决方案.由于生成报表逻辑要从数据库读取大量数据并在内存中加工处理后在 生成大量的汇总数据然后写入到数据库.基本流程是 读取- ...

  5. python mysql connector

    install pip install mysql-connector-python-rf   报错 从https://dev.mysql.com/downloads/connector/python ...

  6. eclipse新建maven项目出现红叉解决办法

    新建的maven项目,项目内代码及pom.xml没有任何问题,但项目上就是有红叉,这时点开Markers(Window–>show veiw–>Markers),查看错误的详细信息,信息上 ...

  7. <a>, <input>, <button>的区分与何时使用

    像 button 的原始目的就是一个通用的按钮,点击后应该触发 JavaScript, 没有其它附带的隐含的附加效果,<a> 标签的隐含附带效果就是跳转页面到其它地方,而提交表单时应该有一 ...

  8. 第八章 高级搜索树 (a2)伸展树:双层伸展

  9. KO ------- 表中字段名和实体类属性名不一致

    -----------------------siwuxie095 KO ------- 表中字段名和实体类属性名不一致 如果数据库表中的字段名和实体类的属性名不一致,那么在查询时, 相应字段的结果就 ...

  10. 在Eclipse中配置Maven插件

    --------------------------siwuxie095                                     在 Eclipse 中配置 Maven 插件     ...