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”,
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

 

题意

f1 = f,f2 = ff, f3 = cff ,fn = fn-1+fn-2

给你一个字符串,问你最少有多少个f里面的东西组成

题解:

坑题,很简单的贪心,把c扔在前面就好

坑点:他可能输入不只是c,f,有可能输入乱七八糟的东西= =

比如caa

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 2000000 + 500
#define mod 10007
#define eps 1e-9
int Num;
char CH[20];
//const int inf=0x7fffffff;   //нчоч╢С
const int inf=0x3f3f3f3f;
//**************************************************************************************

string s;
int main()
{
    int t;scanf("%d",&t);
    for(int cas = 1;cas<=t;cas++)
    {
        cin>>s;
        int flag = 0;
        int st = 0;
        int len = s.size();

        for(int i=0;i<len;i++)
            if(s[i]!='c'&&s[i]!='f')
                flag=2;
        if(flag==2)
        {
            printf("Case #%d: -1\n",cas);
            continue;
        }
        for(int i=0;i<len;i++)
            if(s[i]=='c')
            {
                flag = 1;
                st = i;
                break;
            }

        if(!flag)
        {
            int ans = len/2;
            if(len%2==1)ans++;
            printf("Case #%d: %d\n",cas,ans);
            continue;
        }
        int ans = 0;
        flag = 0;
        int temp = 0;
        temp = 9;
        for(int i=st;i<(st+len);i++)
        {
            if(s[i%len]=='c')
            {
                if(temp<2)
                    flag = 1;
                temp = 0;
                ans++;
            }
            else
                temp++;
        }
        if(temp<2)
            flag = 1;
        if(flag)
            printf("Case #%d: -1\n",cas);
        else
            printf("Case #%d: %d\n",cas,ans);
    }
}

 

    原文作者:qscqesze
    原文地址: https://www.cnblogs.com/qscqesze/p/4822480.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞