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

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<sstream>
typedef long long LL;
const int INF = 0x3f3f3f3f;
using namespace std;
const int MAXN = 1000000 + 10;
const double eps = 1e-8;
int dcmp(double a, double b){
if(fabs(a - b) < eps) return 0;
return a < b ? -1 : 1;
}
struct Trie{
int val;
Trie *nex[26];
Trie(){
val = 0;
for(int i = 0; i < 26; ++i) nex[i] = NULL;
}
};
void build(string x, Trie *root){
int len = x.size();
for(int i = 0; i < len; ++i){
int cur = x[i] - 'a';
if(root -> nex[cur] == NULL){
root -> nex[cur] = new Trie();
}
root = root -> nex[cur];
++root -> val;
}
}
int query(string x, Trie *root){
int len = x.size();
for(int i = 0; i < len; ++i){
int cur = x[i] - 'a';
if(root -> nex[cur] == NULL) return 0;
root = root -> nex[cur];
}
return root -> val;
}
int POW[10];
void init(){
POW[0] = 1;
for(int i = 1; i <= 7; ++i){
POW[i] = POW[i - 1] * 2;
}
}
int main(){
int N, M;
init();
while(scanf("%d%d", &N, &M) == 2){
string s;
Trie *root = new Trie();
for(int i = 0; i < N; ++i){
cin >> s;
build(s, root);
}
int K;
int ans = 0;
while(M--){
scanf("%d", &K);
s = "";
while(K--){
double ave = 0;
double a[10];
for(int i = 0; i < 8; ++i){
scanf("%lf", &a[i]);
ave += a[i];
}
ave /= 8;
int x = 0;
for(int i = 0; i < 8; ++i){
if(a[i] > ave){
x += POW[7 - i] * 1;
}
}
s += x - 97 + 'a';
}
ans += query(s, root);
}
printf("%d\n", ans);
}
return 0;
}

 

HDU - 3724 Encoded Barcodes (字典树)的更多相关文章

  1. hdu 3724 Encoded Barcodes

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

  2. HDU 3724 Encoded Barcodes (Trie)

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

  3. hdu 1671 Phone List 字典树

    // hdu 1671 Phone List 字典树 // // 题目大意: // // 有一些电话号码的字符串长度最多是10,问是否存在字符串是其它字符串的前缀 // // // 解题思路: // ...

  4. hdu 1251 统计难题 (字典树入门题)

    /******************************************************* 题目: 统计难题 (hdu 1251) 链接: http://acm.hdu.edu. ...

  5. HDU 5536 Chip Factory 字典树

    Chip Factory Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...

  6. HDU 1298 T9(字典树+dfs)

    http://acm.hdu.edu.cn/showproblem.php?pid=1298 题意:模拟手机9键,给出每个单词的使用频率.现在给出按键的顺序,问每次按键后首字是什么(也就是要概率最大的 ...

  7. HDU 2846 Repository(字典树,每个子串建树,*s的使用)

    Repository Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  8. HDU 1298 T9【字典树增加||查询】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=1298 T9 Time Limit: 2000/1000 MS (Java/Others)    Memo ...

  9. hdu 1305 Immediate Decodability(字典树)

    Immediate Decodability Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/O ...

随机推荐

  1. python学习 —— python3简单使用pymysql包操作数据库

    python3只支持pymysql(cpython >= 2.6 or >= 3.3,mysql >= 4.1),python2支持mysqldb. 两个例子: import pym ...

  2. Jenkins安装 maven插件

    Maven Artifact ChoiceListProvider (Nexus)Maven Metadata Plugin for Jenkins CI serverMaven Release Pl ...

  3. PHP 三元运算符

    $a = $a ? $a : 1;//第一种 $a = $a ? : 1;//第二种 第二种写法从 PHP 5.3 引入,表示若 $a 返回值为真时,取 $a 的返回值. 此外,在 PHP7 中引入了 ...

  4. 关于AJAX跨域和原生AJAX CORS跨域解决

    项目需求要在别人的域名下调用自己的接口,因为浏览器的同源策略是不允许不同域名下之间的信息交换,那就意味着要跨域处理 参考博客 :https://blog.csdn.net/Ulricalin/arti ...

  5. c/c++ struct的大小以及sizeof用法

    直入主题,怎么判断内存对齐规则,sizeof的结果怎么来的,请牢记以下3条原则:(在没有#pragma pack宏的情况下) 1:数据成员对齐规则:结构(struct)(或联合(union))的数据成 ...

  6. Day3-E-New Year Snowmen CodeForces140C

    As meticulous Gerald sets the table and caring Alexander sends the postcards, Sergey makes snowmen. ...

  7. 循环调用spring的dao,数个过后无响应

    循环调用spring的dao,数个过后无响应 博客分类: spring daospringssh      最近遇到这么一个问题:前台按钮发送AJax请求到后台,后台是SSH框架.每点击一下按钮就发送 ...

  8. js获取cookie提取用户名asp.net+html

    JavaScript是运行在客户端的脚本,因此一般是不能够设置Session的,因为Session是运行在服务器端的. 而cookie是运行在客户端的,所以可以用JS来设置cookie. 假设有这样一 ...

  9. Plcsim 模拟IO访问故障 OB122组织块

    假设在OB1 中用 如下指令 T PQW20 实际在组态的时候就没有QW20 这个地址 所以会显示访问IO 错误 我在OB122 中设置一个变量 进入一次 加1 可以看到每个扫描周期都要调用一次OB1 ...

  10. POJ 3579:Median 差值的中位数

    Median Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4680   Accepted: 1452 Descriptio ...