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. .net entity framework 泛型 更新与增加记录

    static public bool SaveOrUpdate<T>(T entity) where T: class { bool result = false; using (wech ...

  2. ctf总结

    在过去的一个学期中,草人在西普学院还有一些其他安全夺旗网站上刷了一些题,草人我是菜鸟一个,刚开始很是苦恼,所以经历过以后希望将之分享给一起学习安全的同学,目的呢是希望以后学习的人能尽快理清学习思路,进 ...

  3. hdu 4815 Little Tiger vs. Deep Monkey

    概率dp,有点像背包的做法: dp[i][j]代表前i个数组成的j数的概率为多少 #include<cstdio> #include<cstring> #define maxn ...

  4. Firefly框架参考

    在游戏服务器端,往往需要处理大量的各种各样的任务,每一项任务所需的系统资源也可能不同.而这些复杂的任务只用一个单独的服务器进程是很难支撑和管理起来的.所以,游戏服务器端的开发者往往需要花费大量的时间精 ...

  5. glibc, eglibc和 glib的区别

    http://blog.csdn.net/wind19/article/details/6082874

  6. 调试Android USB遇到的令人费解的问题

    上周参照网上代码,做了USB的初步探测程序,工作正常 .今天从硬件部拿到了一段例程,原本打算参考它来完善自己的程序.但运行之后总是报错,逐步跟进错误,进而发现了一个匪疑所思的问题.调试一天也未发现原因 ...

  7. 167. Two Sum II - Input array is sorted

    题目: Given an array of integers that is already sorted in ascending order, find two numbers such that ...

  8. C# 4.0 新特性之并行运算(Parallel)

    介绍C# 4.0 的新特性之并行运算 Parallel.For - for 循环的并行运算 Parallel.ForEach - foreach 循环的并行运算 Parallel.Invoke - 并 ...

  9. 【HDOJ】1114 Piggy-Bank

    DP,先将coins按照重量排序可以优化. #include <stdio.h> #include <stdlib.h> #define MAXNUM 10005 #defin ...

  10. Find the capitals

    Find the capitals Description: Instructions Write a function that takes a single string (word) as ar ...