天天看點

hdu 5455 Fang Fang(2015 ACM/ICPC Asia Regional Shenyang Online) Fang Fang

點選打開連結

time limit: 1500/1000 ms (java/others)    memory limit: 65535/32768 k (java/others)

total submission(s): 531    accepted submission(s): 232

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 = 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 saccording

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