题意:给n个字符串,给m个询问,每个询问给k个条形码。每个条形码由8个小码组成,每个小码有相应的宽度,已知一个条形码的宽度只有2种,宽的表示1,窄的表示0。并且宽的宽度是窄的宽度的2倍。由于扫描的时候有误差,每个小码的宽度为一个浮点型数据,保证每个数据的误差在5%内。所以一个条形码可以对应一个ASCC码,表示一个小写字母。k个条形码表示一个字符串s,每个询问表示给定的m个字符串中以s为前缀的字符串个数。

析:很容易看起来是Tire树, 不知道能不能暴过去,我觉得差不多可以,主要是在处理浮点数上,这个很简单,既然误差这么小,那么我们就可以取最大值和最小值然后除2,小的为0, 大的为1。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#include <list>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 30 * 10000 + 10;
const int mod = 10;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c) {
return r > 0 && r <= n && c > 0 && c <= m;
} struct Trie{
int ch[maxn][26];
int val[maxn];
int sz;
void init(){
memset(ch[0], 0, sizeof ch[0]);
sz = 1;
} int idx(char c){ return c - 'a'; } void insert(char *s){
int u = 0;
for(int i = 0; s[i]; ++i){
int c = idx(s[i]);
if(!ch[u][c]){
memset(ch[sz], 0, sizeof ch[sz]);
val[sz] = 0;
ch[u][c] = sz++;
}
u = ch[u][c];
++val[u];
}
} int query(char *s){
int u = 0;
for(int i = 0; s[i]; ++i){
int c = idx(s[i]);
if(!ch[u][c]) return 0;
u = ch[u][c];
}
return val[u];
}
}; char s[50]; Trie trie;
double a[10]; int main(){
while(scanf("%d %d", &n, &m) == 2){
trie.init();
for(int i = 0; i < n; ++i){
scanf("%s", s);
trie.insert(s);
}
LL ans = 0;
while(m--){
int k;
scanf("%d", &k);
for(int i = 0; i < k; ++i){
double mmin = inf, mmax = -1;
for(int j = 0; j < 8; ++j){
scanf("%lf", a+j);
mmin = min(mmin, a[j]);
mmax = max(mmax, a[j]);
}
double ave = (mmin + mmax) / 2.0;
int t = 0;
for(int j = 0; j < 8; ++j)
if(a[j] < ave) t = t * 2;
else t = t * 2 + 1;
s[i] = t;
}
s[k] = 0;
ans += trie.query(s);
}
printf("%I64d\n", ans);
}
return 0;
}

  

HDU 3724 Encoded Barcodes (Trie)的更多相关文章

  1. hdu 3724 Encoded Barcodes

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

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

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

  3. hdu 4825 Xor Sum(trie+贪心)

    hdu 4825 Xor Sum(trie+贪心) 刚刚补了前天的CF的D题再做这题感觉轻松了许多.简直一个模子啊...跑树上异或x最大值.贪心地让某位的值与x对应位的值不同即可. #include ...

  4. HDU 4776 Ants(Trie+优先队列)

    Ants Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 327680/327680 K (Java/Others) Total S ...

  5. HDU 1671 Phone List (Trie·数组实现)

    链接:http://blog.csdn.net/acvay/article/details/47089657 题意  给你一组电话号码  判断其中是否有某个电话是另一个电话的前缀 字典树的基础应用   ...

  6. HDU 5384 Danganronpa (Trie树)

    题意:给出两个集合S和T,集合中每个元素是个字符串,而T集合中任一元素都是个子弹,可以打S中的任一怪物,如果子弹是怪物的子串,那么才有伤害值1,若在怪物中出现多次,次数为该子弹打到该怪物的伤害值.每个 ...

  7. HDU 4825-Xor Sum(trie)

    题意: 给你一组数,开始询问给一个数  求组中与该数异或值最大的数. 分析:根据异或的特点 要想得到的异或值最大 尽可能的让两个数的每位都相反 先把给定的一组数建树,数的最后一位对应的节点保存这个数的 ...

  8. hdu 1251 统计难题 trie入门

    统计难题 Problem Description Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本 ...

  9. hdu3724Encoded Barcodes(Trie tree)

    题目请戳这里 题目大意:给n个字符串,给m个询问,每个询问给k个条形码.每个条形码由8个小码组成,每个小码有相应的宽度,已知一个条形码的宽度只有2种,宽的表示1,窄的表示0.并且宽的宽度是窄的宽度的2 ...

随机推荐

  1. AUL恢复truncate删除的表

    背景 接到用户申告,新毕业的兄弟不小心把数据库中的3个关键表给truncate了,由于这个业务还在测试阶段,系统没有任何形式的备份. 客户的OS平台是windows平台,数据库是Oracle9207 ...

  2. C#将字符串数组转换为以逗号分隔的字符串

    , tyt, gff }; string str=string.Join(",",array);

  3. Qt5.4中遇到找不到头文件<QApplication>等。

    从新学习Qt时,重装了Qt5.4,当运行Hello World例子时,遇到了下列的情况 <span style="font-size:18px;">#include & ...

  4. java中关于length的真确理解~~~~有补充的请跟帖~~~

    java中的length到底是个什么东西呢?有人说它是一个类,一个方法,如果是方法,它没有括号, 我只知道它可以得出数组的长度,但是今天遇到一段代码,怎么都解释不通,那就是绝对不会把循环的次数与数组的 ...

  5. python中常用模块详解一

    1.time 模块 import time s = time.localtime() # 把时间转化成格式化的时间,通过. 取得里面的年月日等 struct_time 格式 time.struct_t ...

  6. python's eighth day for me

    f : 变量,f_obj, file, f_handler,...文件句柄. open : windows 的系统功能. windows 默认编码方式:gbk.   Linux 默认编码方式:utf ...

  7. 2014.8.25 CAD系统事件触发流程

    各进近.离场.进场Arinc424数据录入界面在CADDataManager/UC/UCIAP(UCSID)下 UCAirport是一抽象用户控件类,在FormADHP初始化时实例化成airport控 ...

  8. 14-jQuery的ajax

    什么是ajax AJAX  =  异步的JavaScript 和 XML (Asynchronous Javascript and XML) 简言之,在不重载整个网页的情况下,AJAX通过后台加载数据 ...

  9. 利用jquery mobiscroll插件选择日期、select、treeList的具体运用

    体验更优排版请移步原文:http://blog.kwin.wang/programming/jquery-mobiscroll-select-treeList.html mobiscroll是个很好用 ...

  10. wordpress get_query_var()函数

    get_query_var函数的最主要作用就是能够查询得到当前文章的分类及分页.定义在:wp-includes/query.php 定义: function get_query_var($var) { ...