zoukankan      html  css  js  c++  java
  • 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 = 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
    ");
    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]=='')
    27       {
    28          printf("Case #%d: ",k);
    29          k++;
    30          printf("%d
    ",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
    ");
    57       else printf("%d
    ",ans);
    58       k++;
    59    }
    60 }
  • 相关阅读:
    Eighth scrum meeting
    Seventh scrum meeting
    Sixth scrum meeting
    Fifth scrum meeting
    Forth scrum meeting
    Third scrum meeting
    2019-07-25 L430 生物 GPS
    L429 Why Do Smart People Do Foolish Things?
    L427 长难句
    L426
  • 原文地址:https://www.cnblogs.com/pblr/p/4822000.html
Copyright © 2011-2022 走看看