HDU - 5455 Fang Fang

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

题目链接: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代码:

 1 #include<stdio.h>
 2 #include<iostream>
 3 #include<algorithm>
 4 #include<string.h>
 5 #include<math.h>
 6 #include<queue>
 7 #include<stdlib.h>
 8
 9 using namespace std;
10 #define N  1010000
11 #define INF 0x3f3f3f3f
12
13 char s[N];
14
15 int main()
16 {
17     int k=1,T,i;
18
19     scanf("%d",&T);
20
21     while(T--)
22     {
23         scanf("%s", s);
24
25         int f=0,ans=0;
26         int len=strlen(s);
27
28         s[len]=s[0];///ffcffc结果是3
29         s[len+1]=s[1];
30
31         for(i=0; i<len; i++)///输入有可能存在其他的字符
32         {
33             if(s[i]==‘c‘||s[i]==‘f‘)
34                 continue ;
35             else
36             {
37                 f=1;
38                 break;
39             }
40         }
41
42         for(i=0;i<len;i++)
43         {
44             if(f==0)
45             {
46                 if(s[i]==‘c‘)
47                 {
48                     if(s[i+1]==‘f‘&&s[i+2]==‘f‘)
49                     {
50                         i++;
51                         while(i<len&&s[i]==‘f‘)///遇见c跳出
52                             i++;
53                         ans++;///个数加一
54                         i--;
55                     }
56                     else
57                         f=1;
58                 }
59             }
60         }
61
62         printf("Case #%d: ",k++);
63         if(f==1)
64             printf("-1\n");
65         else if(ans==0)///全是f
66             printf("%d\n", len/2+len%2);
67         else
68             printf("%d\n", ans);
69     }
70     return 0;
71 }
时间: 2024-10-19 11:36:45

HDU - 5455 Fang Fang的相关文章

hdu 5455 Fang Fang 坑题

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",F

(字符串处理)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)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 233    Accepted Submission(s): 110 Problem Description Fang Fang says she wants to be

Fang Fang HDU - 5455 (思维题)

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", fo

HDU5455 沈阳网络赛 Fang Fang

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=5455 题意是 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 > 2Write down a serenade a

hdu 5455(字符串处理)

Fang Fang Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 1317    Accepted Submission(s): 548 Problem Description Fang Fang says she wants to be remembered.I promise her. We define the sequence

Fang Fang

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 > 2Write down a serenade as a lowercase string S in a circle,

hdu 5455 (2015沈阳网赛 简单题) Fang Fang

题目;http://acm.hdu.edu.cn/showproblem.php?pid=5455 题意就是找出所给字符串有多少个满足题目所给条件的子串,重复的也算,坑点是如果有c,f以外的字符也是不满足条件的,还有我被坑了的地方就是当输入很多f的时候,我尽然脑抽的 认为这是不满足条件的,注意这两点就行了,直接暴力 1 #include<cstdio> 2 #include<cstring> 3 using namespace std; 4 int main() 5 { 6 int

Fang Fang hdu 5455

http://acm.hdu.edu.cn/showproblem.php?pid=5455 题意:判断字符串最少符合题意的个数,它是一个环.若c前面有f,则把f的个数都加到后面去.还有一个坑点是,会有其他字母,不止有c,f. #include <iostream> #include <stdio.h> #include <string.h> #include <string> #include <vector> #include <alg

HDU 5455 Fang Fang 水题,但题意描述有问题

题目大意:f[1]=f,f[2]=ff,f[3]=ffc,以后f[n]每增加1,字符串增加一个c.给出一个字符串,求最少有多少个f[]组成.(字符串首尾相连,比如:ffcf可看做cfff) 题目思路:判断多少个c,但是每个c之间必须有两个f,首尾的c也应判断首尾相连后两者之间的距离.坑点在与 1.给出的字符串中可能包含其它字符 2.严格按照gets()读入 3.若不含c,求有多少个f[2],若有多余补上一个f[1] 3.1.出题人神经病 #include<cstdio> #include<