HDU 4639 Hehe

Hehe

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 57    Accepted Submission(s): 43

Problem Description
As we all know, Fat Brother likes MeiZi every much, he always find some topic to talk with her. But as Fat Brother is so low profile that no one knows he is a rich-two-generation expect the author, MeiZi always rejects him by typing “hehe” (wqnmlgb). You have to believe that there is still some idealized person just like Fat Brother. They think that the meaning of “hehe” is just “hehe”, such like “hihi”, “haha” and so on. But indeed sometimes “hehe” may really means “hehe”. Now you are given a sentence, every “hehe” in this sentence can replace by “wqnmlgb” or just “hehe”, please calculate that how many different meaning of this sentence may be. Note that “wqnmlgb” means “我去年买了个表” in Chinese.
 

 

Input
The first line contains only one integer T, which is the number of test cases.Each test case contains a string means the given sentence. Note that the given sentence just consists of lowercase letters. T<=100 The length of each sentence <= 10086
 

 

Output
For each test case, output the case number first, and then output the number of the different meaning of this sentence may be. Since this number may be quite large, you should output the answer modulo 10007.
 

 

Sample Input
4
wanshangniyoukongme
womenyiqichuqukanxingxingba
bulehehewohaiyoushi
eheheheh
 

 

Sample Output
Case 1: 1
Case 2: 1
Case 3: 2
Case 4: 3
 

 

Source
 

 多校第四场1008,签到题一枚。

首先找出串中有多少处he,每一处都是几个he连在一起的

然后找规律发现对于连续n个he连在一起时,答案与斐波那契数有关,于是问题迎刃而解

可惜啊……比赛时被Case害惨了,Wrong Answer Wrong Answer Wrong Answer……

 

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<vector>
 5 
 6 using namespace std;
 7 
 8 int len;
 9 long f[10000];
10 char s[10100];
11 vector<int> p;
12 
13 void initial()
14 {
15     f[0]=f[1]=1;
16 
17     for(int i=2;i<10000;i++)
18         f[i]=(f[i-1]+f[i-2])%10007;
19 }
20 
21 int main()
22 {
23     int t;
24 
25     initial();
26 
27     scanf("%d",&t);
28     getchar();
29 
30     for(int z=1;z<=t;z++)
31     {
32         gets(s);
33 
34         len=strlen(s);
35         p.clear();
36 
37         for(int i=0;i<len-1;i++)
38         {
39             if(s[i]=='h'&&s[i+1]=='e')
40             {
41                 int times=1;
42                 int j=i+2;
43                 while(s[j]=='h'&&s[j+1]=='e')
44                 {
45                     times++;
46                     j+=2;
47                 }
48                 p.push_back(times);
49                 i=j;
50             }
51         }
52 
53         long result=0;
54 
55         for(int i=0;i<p.size();i++)
56         {
57             if(i)
58                 result=(result*f[p[i]])%10007;
59             else
60                 result=f[p[i]];
61         }
62 
63         if(result==0)
64             result=1;
65 
66         cout<<"Case "<<z<<": "<<result<<endl;
67     }
68 
69     return 0;
70 }
[C++]

 

posted @ 2013-08-01 18:34  ~~Snail~~  阅读(266)  评论(0编辑  收藏  举报