hdu 3724 Encoded Barcodes
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的更多相关文章
- HDU 3724 Encoded Barcodes (Trie)
题意:给n个字符串,给m个询问,每个询问给k个条形码.每个条形码由8个小码组成,每个小码有相应的宽度,已知一个条形码的宽度只有2种,宽的表示1,窄的表示0.并且宽的宽度是窄的宽度的2倍.由于扫描的时候 ...
- HDU - 3724 Encoded Barcodes (字典树)
题意:给定n个字符串和m个经过处理得到的字符串,问对于m个字符串中的每个字符串,n个字符串中以该字符串为前缀的个数.分析:1.误差在[0.95x, 1.05x],因此求8个数的平均数,大于平均数为1, ...
- HDU 1591 Encoded Love-letter(简单字符串)
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...
- UVALive 5029 字典树
E - Encoded Barcodes Crawling in process...Crawling failedTime Limit:3000MS Memory Limit:0KB 6 ...
- B - Encoded Love-letter 字符串的处理
B - Encoded Love-letter Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- HDU 1505 City Game (hdu1506 dp二维加强版)
F - City Game Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submi ...
- hdu 1053 Entropy
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1053 Entropy Description An entropy encoder is a data ...
- Encoded Love-letter
Encoded Love-letter Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) ...
- HDU字符串基础题(1020,1039,1062,1088,1161,1200,2017)
并不是很精简,随便改改A过了就没有再简化了. 1020. Problem Description Given a string containing only 'A' - 'Z', we could ...
随机推荐
- Linux开启服务器问题(李蕾问题)
每次启动192.168.1.223服务器时,都要执行这个命令! #:service iptables stop
- uva 165 Stamps
题意: 现有k种邮票面额, 一封信上最多贴h张邮票. 求能贴出的最大连续区间,即[1, max_value]这个区间内的所有面额都能贴出来. 并输出k种面额, h + k <= 9. 思路: 这 ...
- google 开放I/O源码
在这款应用程序中谷歌对部分功能.API和设计架构进行了非常详细的阐述,其中包括碎片.程序加载.服务.广播.接收器.警告.通知.SQLite数据库.内容提供商.Action Bar.导航Drawer和G ...
- 解决Deprecated: preg_replace(): The /e modifier is deprecated, use
使用php5.5运行ecshop的时候出现如下错误Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace ...
- BZOJ 4004 [JLOI 2015] 装备购买 解题报告
哎这个题 WA 了无数遍...果然人太弱... 首先我们把这些装备按照花费从小到大排序,然后依次考虑是否能买这个装备. 至于这样为什么是对的,好像有一个叫拟阵的东西可以证明,然而我不会.TATQAQ ...
- [XJOI NOI02015训练题7] B 线线线 【二分】
题目链接:XJOI - NOI2015-07 - B 题目分析 题意:过一个点 P 的所有直线,与点集 Q 的最小距离是多少?一条直线与点集的距离定义为点集中每个点与直线距离的最大值. 题解:二分答案 ...
- 关于size_t与size_type
整理自关于size_t与size_type 问题起源于这样一段代码: #include <algorithm> #include <stdio.h> int main() { ...
- UVALive 3211 Now or later
每架飞机有早晚起降两种方式,给定n架飞机两种方式的起落时间,为每架飞机安排起落时间(早或晚),使得所有飞机起降时间按照早到晚的顺序之间的间隔时间最小值尽量大. 分析: 最小时间尽量大应该采用二分的方法 ...
- LCD 和 LED 的区别?
http://sxlecd.blog.163.com/blog/static/131722380200911810564930/
- J2EE的十三种技术(规范)
J2EE的十三种技术(规范) Java数据库连接(JDBC) JDBC API以一个统一的方式访问各种数据库.与ODBC类似,JDBC将开发者和私有数据库之间的问题隔离开来.由于它建立在Java上, ...