zoukankan      html  css  js  c++  java
  • HDU

    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 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
    ");
    65         else if(ans==0)///全是f
    66             printf("%d
    ", len/2+len%2);
    67         else
    68             printf("%d
    ", ans);
    69     }
    70     return 0;
    71 }
  • 相关阅读:
    hdu 5695 Gym Class (拓扑排序)
    bzoj 2002[Hnoi2010]Bounce 弹飞绵羊(分治分块)
    Codeforces Round #355 (Div. 2) D. Vanya and Treasure 分治暴力
    二分图匈牙利模板
    2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 GSM Base Station Identification (点在多边形内模板)
    hdu 1007 Quoit Design (经典分治 求最近点对)
    2017 ACM-ICPC乌鲁木齐网络赛 B. Out-out-control cars(计算几何 直线相交)
    hdu 6146 Pokémon GO (计数)
    hdu 2732 Leapin' Lizards (最大流 拆点建图)
    hdu 1451 Area in Triangle(计算几何 三角形)
  • 原文地址:https://www.cnblogs.com/weiyuan/p/5801882.html
Copyright © 2011-2022 走看看