您的位置:首页 > 其它

HDU 5455 Fang Fang(模拟)

2016-09-01 21:21 274 查看
思路:直接模拟就好了,注意全是f的情况

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ULL;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const double eps = 1e-9;
const int maxn = 1000000 + 100;
char s[maxn];
int pos[maxn];

int main()
{
int T, cas=1, n;
scanf("%d", &T);
while(T--)
{
int f=1, cn=0;
scanf("%s", s);
n = strlen(s);
for(int i=0;s[i];++i)
{
if(s[i]=='c') pos[cn++]=i;
if(s[i]!='c'&&s[i]!='f'){
f=0; break;
}
}
printf("Case #%d: ", cas++);

if(!f) puts("-1");
else
{
if(cn==0)
{
printf("%d\n", n/2+n%2);
continue;
}

for(int i=0;i<cn-1;++i)
{
if(pos[i+1]-pos[i]<3)
{
f=0; break;
}
}
if(n-pos[cn-1] + pos[0] < 3) f=0;
if(!f) puts("-1");
else printf("%d\n", cn);
}

}

return 0;
}


Description

Fang Fang says she wants to be remembered. 

I promise her. We define the sequence 

 of
strings. 




















 






















 
























 






















































 

Write down a serenade as a lowercase string 

 in
a circle, in a loop that never ends. 

Spell the serenade using the minimum number of strings in 

,
or nothing could be done but put her away in cold wilderness.

Input

An positive integer 

,
indicating there are 

 test
cases. 

Following are 

 lines,
each line contains an string 

 as
introduced above. 

The total length of strings for all test cases would not be larger than 





.

Output

The output contains exactly 

 lines. 

For each test case, if one can not spell the serenade by using the strings in 

,
output 



.
Otherwise, output the minimum number of strings in 

 to
split 

 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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: