题意:给定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. 通过命令行提交更新代码到gitlab上

    解决方法: 1.打开命令行的窗口,定位到项目所在的路径. 2.输入:git status,敲回车查看代码是否有更新,有更新的话会出现文件改变的文件名.(红色的) 3.输入:git commit -a ...

  2. Using webpack-dev-server

    官方讲解地址:https://webpack.js.org/guides/development/#using-webpack-dev-server The webpack-dev-server pr ...

  3. window查看连接过的无线密码

    for /f "skip=9 tokens=1,2 delims=:" %i in ('netsh wlan show profiles') do  @echo %j | find ...

  4. unity 骨骼 蒙皮

    https://blog.csdn.net/weixin_44350205/article/details/100551233 https://www.jianshu.com/p/d5e2870eb3 ...

  5. Redis第一篇章 Hello Word!

    1.找到redis目录 2.在新建一个文件夹(myredis) 3.将redis.conf 进行复制到myredis 文件夹里面 4.启动redis redis-server /home/dc2-us ...

  6. INUX下抓取当前登录用户登录密码的工具:mimipenguin

    前有Mimikatz,今有mimipenguin,近日国外安全研究员huntergregal发布了工具mimipenguin,一款Linux下的密码抓取神器,可以说弥补了Linux下密码抓取的空缺. ...

  7. Manthan, Codefest 19(Div. 1 + Div. 2)

    传送门 A. XORinacci 签到. Code /* * Author: heyuhhh * Created Time: 2020/2/26 9:26:33 */ #include <ios ...

  8. Django 3.0 中连接mysql 8.0,可以不使用pymysql ,升级Mysqlclient即可

    python 中,连接mysql一般都推荐用pymysql ,而且在django中,网上的教程都是这么连接mysql的. import pymysql pymysql.install_as_MySQL ...

  9. Centos7 下vmware NAT模式配置网络连接与DNS

    NAT模式配置网络 1.首先查看NAT模式下的网络 从这边可以知道我的vmware下的nat模式的网络是192.168.109.*网段 上图这个网段也可以修改为别的网段 2.NAT模式下的网关 3.配 ...

  10. 常用mac/unix/linux命令

    1.查询ip地址 ifconfig 2.查找服务器上应用程序的端口分配 grep telnet /etc/services (telnet) telnet使用TCP/UDP端口号23 grep dom ...