HDU - 3724 Encoded Barcodes (字典树)
题意:给定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 (字典树)的更多相关文章
- hdu 3724 Encoded Barcodes
Trie模板.把所有单词都用字典树存起来,然后给每个节点赋权值表示前缀到该节点出现了几次.然后直接查询就可以了. #include <algorithm> #include <ios ...
- HDU 3724 Encoded Barcodes (Trie)
题意:给n个字符串,给m个询问,每个询问给k个条形码.每个条形码由8个小码组成,每个小码有相应的宽度,已知一个条形码的宽度只有2种,宽的表示1,窄的表示0.并且宽的宽度是窄的宽度的2倍.由于扫描的时候 ...
- hdu 1671 Phone List 字典树
// hdu 1671 Phone List 字典树 // // 题目大意: // // 有一些电话号码的字符串长度最多是10,问是否存在字符串是其它字符串的前缀 // // // 解题思路: // ...
- hdu 1251 统计难题 (字典树入门题)
/******************************************************* 题目: 统计难题 (hdu 1251) 链接: http://acm.hdu.edu. ...
- HDU 5536 Chip Factory 字典树
Chip Factory Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...
- HDU 1298 T9(字典树+dfs)
http://acm.hdu.edu.cn/showproblem.php?pid=1298 题意:模拟手机9键,给出每个单词的使用频率.现在给出按键的顺序,问每次按键后首字是什么(也就是要概率最大的 ...
- HDU 2846 Repository(字典树,每个子串建树,*s的使用)
Repository Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- HDU 1298 T9【字典树增加||查询】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=1298 T9 Time Limit: 2000/1000 MS (Java/Others) Memo ...
- hdu 1305 Immediate Decodability(字典树)
Immediate Decodability Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/O ...
随机推荐
- git 常用命令记录 -- 快捷&备忘
1.安装 略2.git拉取远程分支 git config user.name git config user.email git config --global user.name xxxx git ...
- webpack配置文件里loader的执行顺序:从下到上,从右到左; css-loader开启css模块化modules: true,
注释: options:{ importLoaders: 2 } 解决样式文件里使用@import 'xxx.xxx' 的问题 module: { rules: [{ test: /\.scss$/, ...
- Jsp补充
留在这里日后出错可查 <%@ page language="java" import="java.util.*,java.lang.*" pageEnco ...
- ABC154F - Many Many Paths
梦回高中,定义的f(i,j)为从(0,0)到(i,j)一共有多少条路可以选择,易知我们要做i+j次选择,其中有i次是选择x轴,剩下的是y轴,所以f(i,j)=C(i+j,i)=C(i+j,j),给你一 ...
- windows下安装redis并部署服务
下载地址: windows版本: https://github.com/MSOpenTech/redis/releases Linux版本: 官网下载: http://www.redis.cn/ gi ...
- 【转帖】IBM发布全新闪存解决方案,助企业存储架构做减法
IBM发布全新闪存解决方案,助企业存储架构做减法 http://stor-age.zhiding.cn/stor-age/2020/0227/3124851.shtml 感觉 配图弄错了 FlashS ...
- Linux之网络配置
Linux系统网络设备配置文件在/etc/sysconfig/network-scripts/目录中,可使用Vim编辑器编辑网卡配置文件,来配置网络服务,在RHEL7中,网卡配置文件以前缀ifcfg开 ...
- kafka在zookeeper默认使用/为根目录,将/更换为/kafka
需求:kafka在zookeeper默认使用/为根目录,将/更换为/kafka 步骤:1.进入kafka的根目录: [root@node01 kafka_2.11-1.0.0]# cd /export ...
- 「NOIP2015」运输计划
传送门 Luogu 解题思路 首先这题可以直接二分答案,然后我们每次都把属于长度大于二分值的路径上的边标记一次,表示选这条边可以优化几条路径. 然后我们显然是要选一条覆盖次数等于需要覆盖的路径数并且长 ...
- Hibernate一对多(多对一)外键设置汇总
我打算在角色表(role)中添加一个帐号表(account)的外键(accountId),步骤如下: 1.首先在角色表(role)中添加列. 添加语句:alter table role add(acc ...