码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 5455 Fang Fang

时间:2015-09-19 19:34:57      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:

 

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 = Fn1 + 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 }

 

hdu 5455 Fang Fang

标签:

原文地址:http://www.cnblogs.com/pblr/p/4822000.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!