题意大致如下:屌丝找女神聊天,女神回了一句 hehe ,而我们都知道 Hehe 有两个意思,一个就是 Hehe ,另外一个则是 wqnmlgb (我去年买了个表) ,所以屌丝很纠结,于是开始思考到底女神是什么意思,现在屌丝想知道女神的一句话究竟有多少种意思?

这题的定位是签到题,很水。

从题目给的第四组测试数据 eheheheh ,对应的答案是 3 种情况,由此分析(我下面用 H 表示 he ,用 W 表示 wqnmlgb):
第三组数据:   eHHHh

可能的情况就是:eWHh   eHWh eHHHh 这三种。

下面进一步扩展一下,将第三组数据简化成 HHH ,因为开始和结尾的两个字符不是会有歧义的 Hehe 。所以我们可以推出下表:

H                   ---               1

HH                 ---               2

HHH               ---               3

HHHH             ---               5

HHHHH           ---               8

从这五组数据就能看出,连续的 H 能造成的歧义是斐波那契数列。然后,就是讨论不连续的 H 。看下面这个例子:

ahehebhehe

这个例子的答案很显然是 4 。这个数据简化一下变成 HHbHH 。注意,这里由于不连续,所以中间的 b 不能删掉。所以四种情况就是 HHbW   WbHH   WbW   HHbHH 。分析下就可以得出 4 是由 1 * 2 * 2 得来的。因为每一段 H 都可以独立的变化,互相不影响。由之前得到的斐波那契数列可以知道,HH 可以造成 2 种意思,然后因为有两组 HH ,且互相独立。所以直接相乘。

然后题目分析到这里,就已经非常明朗了,我们需要做的就是把所有连续 H 造成的歧义数相乘就OK了。所以,用预处理斐波那契数列,然后扫一趟输入的字符串就能得出答案了。

P.s :需要注意答案要对 10007 取模。

附AC代码:

   1: #include <stdio.h>

   2: #include <math.h>

   3: #include <iostream>

   4: #include <cstdarg>

   5: #include <algorithm>

   6: #include <string.h>

   7: #include <stdlib.h>

   8: #include <string>

   9: #include <list>

  10: #include <vector>

  11: #include <map>

  12: #define LL long long

  13: #define M(a) memset(a, 0, sizeof(a))

  14: using namespace std;

  15:  

  16: void Clean(int count, ...)

  17: {

  18:     va_list arg_ptr;

  19:     va_start (arg_ptr, count);

  20:     for (int i = 0; i < count; i++)

  21:         M(va_arg(arg_ptr, int*));

  22:     va_end(arg_ptr);

  23: }

  24: int buf[10089];

  25:  

  26: void Pre()

  27: {

  28:     buf[0] = 1;

  29:     buf[1] = 2;

  30:     for (int i = 2; i <= 10087; i++)

  31:     {

  32:         buf[i] = (buf[i - 1] + buf[i - 2]) % 10007;

  33:  

  34:     }

  35:     return ;

  36: }

  37:  

  38: int main()

  39: {

  40:     char hehe[10099];

  41:     Clean(2, buf, hehe);

  42:     Pre();

  43:     int T;

  44:     scanf("%d", &T);

  45:     for (int cnt = 1; cnt <= T; cnt++)

  46:     {

  47:         scanf("%s", hehe);

  48:         printf("Case %d: ", cnt);

  49:         int res = 1;

  50:         int tmp = 0;

  51:         for (int i = 0; i < strlen(hehe); i++)

  52:         {

  53:             if (hehe[i] == 'h')

  54:             {

  55:                 while (hehe[i] == 'h' && i < strlen(hehe))

  56:                 {

  57:                     if (hehe[i + 1] == 'e' && hehe[i + 2] == 'h' && hehe[i + 3] == 'e')

  58:                         tmp += 1;

  59:                     else

  60:                     {

  61:                         res *= buf[tmp];

  62:                         res %= 10007;

  63:                         tmp = 0;

  64:                         break;

  65:                     }

  66:                     i += 2;

  67:                 }

  68:             }

  69:         }

  70:         res *= buf[tmp];

  71:         res %= 10007;

  72:         printf("%d\n", res);

  73:     }

  74:     return 0;

  75: }

HDU 4639 Hehe 2013 Multi-University Training Contest 4的更多相关文章

  1. HDU 4639 Hehe (2013多校4 1008 水题)

    Hehe Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  2. hdu 4930 Fighting the Landlords--2014 Multi-University Training Contest 6

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4930 Fighting the Landlords Time Limit: 2000/1000 MS ...

  3. HDU 6143 - Killer Names | 2017 Multi-University Training Contest 8

    /* HDU 6143 - Killer Names [ DP ] | 2017 Multi-University Training Contest 8 题意: m个字母组成两个长为n的序列,两序列中 ...

  4. HDU 6074 - Phone Call | 2017 Multi-University Training Contest 4

    看标程的代码这么短,看我的.... 难道是静态LCA模板太长了? /* HDU 6074 - Phone Call [ LCA,并查集 ] | 2017 Multi-University Traini ...

  5. HDU 6068 - Classic Quotation | 2017 Multi-University Training Contest 4

    /* HDU 6068 - Classic Quotation [ KMP,DP ] | 2017 Multi-University Training Contest 4 题意: 给出两个字符串 S[ ...

  6. HDU 6076 - Security Check | 2017 Multi-University Training Contest 4

    /* HDU 6076 - Security Check [ DP,二分 ] | 2017 Multi-University Training Contest 4 题意: 给出两个检票序列 A[N], ...

  7. HDU 6071 - Lazy Running | 2017 Multi-University Training Contest 4

    /* HDU 6071 - Lazy Running [ 建模,最短路 ] | 2017 Multi-University Training Contest 4 题意: 四个点的环,给定相邻两点距离, ...

  8. HDU 6078 - Wavel Sequence | 2017 Multi-University Training Contest 4

    /* HDU 6078 - Wavel Sequence [ DP ] | 2017 Multi-University Training Contest 4 题意: 给定 a[N], b[M] 要求满 ...

  9. HDU 6070 - Dirt Ratio | 2017 Multi-University Training Contest 4

    比赛时会错题意+不知道怎么线段树维护分数- - 思路来自题解 /* HDU 6070 - Dirt Ratio [ 二分,线段树 ] | 2017 Multi-University Training ...

随机推荐

  1. python-time,datetime

    1.time模块:time.time() # 返回当前时间的时间戳(1970纪元后经过的浮点秒数)time.localtime([ sec ]) # 接收时间戳(默认为当前时间),返回struct_t ...

  2. am335x system upgrade uboot nand boot(三)

    在uboot 下初始化nand,一般需要做如下工作: 第一: 配置默认从NAND boot Index: include/configs/am335x_evm.h=================== ...

  3. os 模块 和 os模块下的path模块

    import os # os 主要用于与操作系统进行交互 #获取当前的工作目录 print(os.getcwd()) #切换工作目录 os .chdir("D:\上海python全栈4期\d ...

  4. windows上dubbo-admin的安装

    dubbo-admin的安装 (1)先下载好zookeeper包,因为启动dubbo-admin时需要先启动zookeeper zookeeper:dubbo的注册中心(自己下载 ,找到bin目录下的 ...

  5. 十九. Python基础(19)--异常

    十九. Python基础(19)--异常 1 ● 捕获异常 if VS异常处理: if是预防异常出现, 异常处理是处理异常出现 异常处理一般格式: try:     <............. ...

  6. 四. Python基础(4)--语法

    四. Python基础(4)--语法 1 ● 比较几种实现循环的代码 i = 1 sum = 0 while i <= 10: # 循环10-1+1=10次     sum += i     i ...

  7. HDU - 2819 Swap(二分图最大匹配)

    Given an N*N matrix with each entry equal to 0 or 1. You can swap any two rows or any two columns. C ...

  8. 2019.3.22 Week 11 : ZigBee power test and field test

    Test require Zigbee sample:EFR32MG13  (RF layout has ) Gateway N4010A : 2.5Ghz 1Power test 2Field te ...

  9. 关于urls 的基础

    1 普通正则 2 分组正则 url(r'/blog/(\d+)/(\d+)',views.blog)     blog(request,arq1,arq2) 按照位置传参 3 分组命名 url(r'/ ...

  10. intellij怎么导入MySQL的驱动包

    1.下载zip格式的驱动包:https://dev.mysql.com/downloads/connector/j/ 2.解压zip,放到任意位置.其中的mysql-connector-java.ja ...