Trie模板。把所有单词都用字典树存起来,然后给每个节点赋权值表示前缀到该节点出现了几次。然后直接查询就可以了。

#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <climits>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <cctype>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#define CLR(a, b) memset(a, b, sizeof(a))
using namespace std; const int MAX_NODE = 10100 * 66;
const int INF = 0x3f3f3f3f;
const int MOD = 20090717;
const int CHILD_NUM = 26;
const int N = 30; class Trie
{
private:
int chd[MAX_NODE][CHILD_NUM];
int val[MAX_NODE];
int Q[MAX_NODE];
int ID[128];
int sz;
public:
void Initialize()
{
for(int i = 0; i < 26; i ++)
ID[i + 'a'] = i;
}
void Reset()
{
CLR(chd[0] , 0);sz = 1;
CLR(val, 0);
}
void Insert(char *a)
{
int p = 0;
for ( ; *a ; a ++)
{
int c = ID[*a];
if (!chd[p][c])
{
CLR(chd[sz] , 0);
chd[p][c] = sz ++;
}
p = chd[p][c];
val[p] ++;
}
}
int Work()
{
int q, now, S = 0;
double tmp[10], lg;
scanf("%d", &q);bool flag = 0;
for(int i = 0; i < q; i ++)
{
lg = 1e18;
for(int j = 0; j < 8; j ++)
{
scanf("%lf", &tmp[j]);
lg = min(lg, tmp[j]);
}now = 0;
for(int j = 0; j < 8; j ++)
{
now <<= 1;
if(tmp[j] > lg * 1.105)
now += 1;
}
if(!flag)S = chd[S][ID[now]];
if(!S) flag = 1;
}
if(!flag) return val[S];
else return 0;
}
} Tr; char ch[N]; int main()
{
//freopen("input.txt", "r", stdin);
Tr.Initialize();
int n, m, k, ans;
while (scanf("%d%d", &n, &m) != EOF)
{
Tr.Reset();
for (int i = 0 ; i < n ; i ++)
{
char temp[66];
scanf("%s", temp);
Tr.Insert(temp);
}
ans = 0;
for(int i = 0; i < m; i ++)
ans += Tr.Work();
printf("%d\n", ans);
}
return 0;
}

hdu 3724 Encoded Barcodes的更多相关文章

  1. HDU 3724 Encoded Barcodes (Trie)

    题意:给n个字符串,给m个询问,每个询问给k个条形码.每个条形码由8个小码组成,每个小码有相应的宽度,已知一个条形码的宽度只有2种,宽的表示1,窄的表示0.并且宽的宽度是窄的宽度的2倍.由于扫描的时候 ...

  2. HDU - 3724 Encoded Barcodes (字典树)

    题意:给定n个字符串和m个经过处理得到的字符串,问对于m个字符串中的每个字符串,n个字符串中以该字符串为前缀的个数.分析:1.误差在[0.95x, 1.05x],因此求8个数的平均数,大于平均数为1, ...

  3. HDU 1591 Encoded Love-letter(简单字符串)

    Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...

  4. UVALive 5029 字典树

    E - Encoded Barcodes Crawling in process...Crawling failedTime Limit:3000MS    Memory Limit:0KB    6 ...

  5. B - Encoded Love-letter 字符串的处理

    B - Encoded Love-letter Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & % ...

  6. HDU 1505 City Game (hdu1506 dp二维加强版)

    F - City Game Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submi ...

  7. hdu 1053 Entropy

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1053 Entropy Description An entropy encoder is a data ...

  8. Encoded Love-letter

    Encoded Love-letter Time Limit : 1000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) ...

  9. HDU字符串基础题(1020,1039,1062,1088,1161,1200,2017)

    并不是很精简,随便改改A过了就没有再简化了. 1020. Problem Description Given a string containing only 'A' - 'Z', we could ...

随机推荐

  1. tableView -- tips

    1. 如果发现TableView的第一个sectionHeader不显示, 那么可以断定, 你没有用代理方法来设置 sectionHeader的高度! #pragma mark - delegate ...

  2. Codeforces Round #326 div2

    Problem_A(588A): 题意: Duff 很喜欢吃肉, 每天都要吃,然而她又懒得下楼. 可以买很多放在家里慢慢吃.然而肉价每天都在变化,现给定一个n, 表示有多少天,然后第i天吃ai kg的 ...

  3. 《ASP.NET 本质论》HttpApplication的处理管道 ,HttpMoudle,HttpHandler

    http://blog.csdn.net/sky1069/article/details/6659667 handler :http://blog.csdn.net/keymo_/article/de ...

  4. 让Eclipse使用新版本的JRE

    更新到新的 Mac OS X 再打开Eclipse 编译程序会报错, Exception in thread "main" java.lang.UnsupportedClassVe ...

  5. 什么是 DevSecOps?系列(一)

    什么是 DevSecOps? 「DevSecOps」 的作用和意义建立在「每个人都对安全负责」的理念之上,其目标是在不影响安全需求的情况下快速的执行安全决策,将决策传递至拥有最高级别环境信息的人员. ...

  6. ****Objective-C 中的方法的调用

    oc语言中采用特定的语言调用类或者实例(对象)的方法称为发送消息或者方法调用. oc中方法的调用有两种: 第一种: [类名或对象名 方法名]; [ClassOrInstance method]; [C ...

  7. 物理地址为20位 如10000H 用段地址*16+偏移地址表示

    段地质在cpu中,为16位 段地质*16则变成物理首地址20位,这个物理首地址必定是16的倍数. 偏移地址16位, 则表明一个段的大小为64k. 同时也表明16位地址的寻址能力为64kb

  8. yii

    2008年出现的一个以php为基础的框架,特点是:高性能框架.代码重用性.速度非常快(改完代码后直接刷新就可以展示修改后的页面).有小物件.登录组件.日志组件等等. main.php配置与数据库相连的 ...

  9. Spring学习笔记(二)

    1.Spring MVC 返回json数据 <bean class="org.springframework.web.servlet.mvc.annotation.Annotation ...

  10. jQuery 插件模板

    1.为每一个DOM对象创建一个插件对象 模板定义: (function($) { $.pluginName = function(element, options) { var defaults = ...