hdu 5455 Fang Fang 坑题

时间:2023-12-19 09:38:32

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[];
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
//************************************************************************************** string s;
int main()
{
int t;scanf("%d",&t);
for(int cas = ;cas<=t;cas++)
{
cin>>s;
int flag = ;
int st = ;
int len = s.size(); for(int i=;i<len;i++)
if(s[i]!='c'&&s[i]!='f')
flag=;
if(flag==)
{
printf("Case #%d: -1\n",cas);
continue;
}
for(int i=;i<len;i++)
if(s[i]=='c')
{
flag = ;
st = i;
break;
} if(!flag)
{
int ans = len/;
if(len%==)ans++;
printf("Case #%d: %d\n",cas,ans);
continue;
}
int ans = ;
flag = ;
int temp = ;
temp = ;
for(int i=st;i<(st+len);i++)
{
if(s[i%len]=='c')
{
if(temp<)
flag = ;
temp = ;
ans++;
}
else
temp++;
}
if(temp<)
flag = ;
if(flag)
printf("Case #%d: -1\n",cas);
else
printf("Case #%d: %d\n",cas,ans);
}
}