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 ...
随机推荐
- Chapter 10 EF 6 Support
http://dev.mysql.com/doc/connector-net/en/connector-net-entityframework60.html
- JQ+AJAX实现多级联动
利用JQ与AJAX实现三级联动实现的效果: 当前两级改变时,后边一级或两级都会改变: 使用的数据库: html代码: <!doctype html> <html lang=" ...
- c语言通过89C51驱动1602液晶显示(入门级别)
工具proteus,keil 步骤: 1.画好电路图 2.在指令模式下,设置好显示模式以及光标位置 3.在写数据模式下,向1602写入显示字符(1602只能显示数字和字符) 电路图 #include ...
- poj 3373 Changing Digits (DFS + 记忆化剪枝+鸽巢原理思想)
http://poj.org/problem?id=3373 Changing Digits Time Limit: 3000MS Memory Limit: 65536K Total Submi ...
- C# 操作mongodb 分组
c#操作mongodb的分组的简单例子: 1.首先要下载c#对应的mongodb驱动,官方下载地址:https://github.com/mongodb/mongo-csharp-driver/rel ...
- C#变成数据导入Excel和导出Excel
excel 基础 •整个excel 表格叫工作表:workbook:工作表包含的叫页:sheet:行:row:单元格:cell. •excel 中的电话号码问题,看起来像数字的字符串以半角单引号开头就 ...
- APT攻防对抗
APT(高级持续性威胁)攻击是指近年来,专业甚至是有组织和国家背景支持的黑客,针对重要目标和系统发起的一种攻击手段,主要特征有 1)持续性:攻击者为了重要的目标长时间持续攻击直到攻破为止.攻击成功用上 ...
- HDU3362+状态压缩
dp[ i ]表示该状态下得所需花费. /* 状态压缩dp dp[i] = min( dp[ i-j ]+cost[ j ] ); 由i-j的状态转到i的状态 */ #include<stdio ...
- [jobdu]用两个栈实现队列
思路比较简单.就是当要pop的时候,如果s2为空,才把s1的转过来.总之就是区分一下此时s2为空和非空的情况. http://ac.jobdu.com/problem.php?pid=1512 #in ...
- eCos中断模型
http://blog.csdn.net/chychc/article/details/8313458 http://www.cnblogs.com/RandyQ/archive/2013/04/14 ...