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.
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.
//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);
}
}