HDU 3724 Encoded Barcodes (Trie)
题意:给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)的更多相关文章
- hdu 3724 Encoded Barcodes
Trie模板.把所有单词都用字典树存起来,然后给每个节点赋权值表示前缀到该节点出现了几次.然后直接查询就可以了. #include <algorithm> #include <ios ...
- HDU - 3724 Encoded Barcodes (字典树)
题意:给定n个字符串和m个经过处理得到的字符串,问对于m个字符串中的每个字符串,n个字符串中以该字符串为前缀的个数.分析:1.误差在[0.95x, 1.05x],因此求8个数的平均数,大于平均数为1, ...
- hdu 4825 Xor Sum(trie+贪心)
hdu 4825 Xor Sum(trie+贪心) 刚刚补了前天的CF的D题再做这题感觉轻松了许多.简直一个模子啊...跑树上异或x最大值.贪心地让某位的值与x对应位的值不同即可. #include ...
- HDU 4776 Ants(Trie+优先队列)
Ants Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 327680/327680 K (Java/Others) Total S ...
- HDU 1671 Phone List (Trie·数组实现)
链接:http://blog.csdn.net/acvay/article/details/47089657 题意 给你一组电话号码 判断其中是否有某个电话是另一个电话的前缀 字典树的基础应用 ...
- HDU 5384 Danganronpa (Trie树)
题意:给出两个集合S和T,集合中每个元素是个字符串,而T集合中任一元素都是个子弹,可以打S中的任一怪物,如果子弹是怪物的子串,那么才有伤害值1,若在怪物中出现多次,次数为该子弹打到该怪物的伤害值.每个 ...
- HDU 4825-Xor Sum(trie)
题意: 给你一组数,开始询问给一个数 求组中与该数异或值最大的数. 分析:根据异或的特点 要想得到的异或值最大 尽可能的让两个数的每位都相反 先把给定的一组数建树,数的最后一位对应的节点保存这个数的 ...
- hdu 1251 统计难题 trie入门
统计难题 Problem Description Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本 ...
- hdu3724Encoded Barcodes(Trie tree)
题目请戳这里 题目大意:给n个字符串,给m个询问,每个询问给k个条形码.每个条形码由8个小码组成,每个小码有相应的宽度,已知一个条形码的宽度只有2种,宽的表示1,窄的表示0.并且宽的宽度是窄的宽度的2 ...
随机推荐
- 连续创建多个Oracle触发器失败,单个创建才成功的解决方法
当用到自增序列,需要用到触发器的时候,当我连续执行创建多个触发器时,总是报编译通过,但存在警告或错误. ---.应用信息 drop table app_info cascade constraints ...
- 数据科学:numpy.where() 的用法
原文出处:numpy.where() 用法讲解 原创作者:massquantity numpy.where() 有两种用法: 1. np.where(condition, x, y) 满足条件(con ...
- CommonJS、CMD和AMD规范分别是什么
CommonJS.CMD和AMD规范分别是什么 Commonjs是用在服务器端的,同步的,如nodejs amd, cmd是用在浏览器端的,异步的,如requirejs和seajs 其中,amd先提出 ...
- VS配置附加包含目录技巧
把include文件夹(里面是某个库的头文件)拷到自己的项目中,添加头文件时需要使用#include"include\xxx.h"方式,如果打算使用#include"xx ...
- 数据结构(c语言描述)
预备的数学知识 数据结构的概念 基本名词 算法 线性表 线性表的定义和基本操作 顺序表 顺序表增 顺序表删 顺序表查 单链表 建立单链表 单链表增 单链表删 单链表查 双链表 循环链表 静态链表 栈 ...
- python利用scapy模块写一个TCP路由追踪和扫描存活IP的脚本
前言: 没有前言 0x01 from scapy.all import * import sys from socket import * import os from threading impor ...
- Linux批量“解压”JAR文件
当你需要”解压“很多jar文件时,可以通过很多方式进行,比如下面这种 1,列出每一个jar文件名,逐个展开 for i in $(ls *sour*.jar);do jar xvf $i;done
- 手机自带输入法emoji表情的输入,提交及显示——前端解决方案
体验更优排版请移步原文:http://blog.kwin.wang/programming/emoji-transform-commit.html 之前就遇到过需要前端支持用户输入并提交emoji表情 ...
- CSS JQuyer 元素选择
$(this) 当前 HTML 元素 $("p") 所有 <p> 元素 $("p.intro") 所有 class="intro" ...
- Apache Shiro 权限框架
分享一个视屏教程集合 http://www.tudou.com/home/konghao/item 1.Shiro Apache Shiro是一个强大且易用的Java安全框架,执行身份验证.授权.密码 ...