用字典树来查询,关键是怎么处理输入的8个数字代表的字符,把每个数分别除以0.95和1.05得到8的区间,按左区间从小到大排序,那么和第一个区间有交集的必然代表二进制0,与它没交集的之后都是1,因为题目保证输入数据是合法的.

#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const double eps = 1e-6;
struct Width{
int idx;
double val, l, r;
Width(int idx, double val){
this->val = val;
this->idx = idx;
this->r = val/0.95;
this->l = val/1.05;
}
bool operator < (const Width &A) const {
if(fabs(l - A.l) < eps) return r + eps < A.r;
return l + eps < A.l;
}
bool isInRange(const Width &A){
return r + eps > A.l;
}
};
struct Node{
int cnt;
Node *child[26];
Node(){
cnt = 0;
for(int i = 0;i < 26;i ++) child[i] = NULL;
}
};
Node *root;
vector<Width>V;
void insertTrie(char str[]){
Node* tmp = root;
while(str[0]){
int idx = str[0]-'a';
if(tmp->child[idx] == NULL) tmp->child[idx] = new Node();
tmp = tmp->child[idx];
tmp->cnt ++;
str++;
}
}
int searchTrie(char str[]){
Node *tmp = root;
while(str[0]){
int idx = str[0]-'a';
if(tmp->child[idx] == NULL) return 0;
tmp = tmp->child[idx];
str++;
}
return tmp->cnt;
}
char fuckAuthorAndFuckAuthorMother(){
int pos, ret(0);
sort(V.begin(), V.end());
for(int i = 1;i < V.size();i ++){
if(V[0].isInRange(V[i])) continue;
pos = i;
break;
}
for(int i = pos;i < V.size();i ++) ret |= (1 << V[i].idx);
return ret;
}
int main(){
int n, m, t;
char str[50];
freopen("in.cpp", "r", stdin);
while(~scanf("%d%d", &n, &m)){
root = new Node();
for(int i = 0;i < n;i ++){
scanf("%s", str);
insertTrie(str);
}
int ans = 0;
for(int i = 0;i < m;i ++){
scanf("%d", &t);
memset(str, 0, sizeof str);
for(int j = 0;j < t;j ++){
V.clear();
double tmp;
for(int k = 7;k >= 0;k --){
scanf("%lf", &tmp);
V.push_back(Width(k, tmp));
}
str[j] = fuckAuthorAndFuckAuthorMother();
}
//printf("str = %s\n", str);
ans += searchTrie(str);
}
printf("%d\n", ans);
}
return 0;
}

UVALive 5029的更多相关文章

  1. UVALive 5029 字典树

    E - Encoded Barcodes Crawling in process...Crawling failedTime Limit:3000MS    Memory Limit:0KB    6 ...

  2. UVALive - 4108 SKYLINE[线段树]

    UVALive - 4108 SKYLINE Time Limit: 3000MS     64bit IO Format: %lld & %llu Submit Status uDebug ...

  3. UVALive - 3942 Remember the Word[树状数组]

    UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...

  4. UVALive - 3942 Remember the Word[Trie DP]

    UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...

  5. 思维 UVALive 3708 Graveyard

    题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...

  6. UVALive 6145 Version Controlled IDE(可持久化treap、rope)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  7. HDU 5029 Relief grain(离线+线段树+启发式合并)(2014 ACM/ICPC Asia Regional Guangzhou Online)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5029 Problem Description The soil is cracking up beca ...

  8. UVALive 6508 Permutation Graphs

    Permutation Graphs Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit ...

  9. UVALive 6500 Boxes

    Boxes Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Pract ...

随机推荐

  1. POJ3009Curling 2.0

    http://poj.org/problem?id=3009 题意 : 迷宫升级版,也是m*n的迷宫,0是可以走的,1是阻塞,2是初始点,3是目标位置,这个的阻塞是可以消除的,就是说只要石头撞到阻塞, ...

  2. 关于Model层中Datetime Datetime? 默认值的问题

    DateTime 和 DateTime?前者不允许为空,会有默认值,而DateTime?可以为Null 其他数值型同理!

  3. Spring整合Ibatis

    Spring整合Ibatis javaibatisspring 所需jar清单           ibatis-2.*.jar    *为任意版本,下同,ibatis工作包           sp ...

  4. python 常用数据结构使用

    python 字典操作 http://www.cnblogs.com/kaituorensheng/archive/2013/01/24/2875456.html python 字典排序 http:/ ...

  5. HDU5099——Comparison of Android versions(简单题)(2014上海邀请赛重现)

    Comparison of Android versionsProblem DescriptionAs an Android developer, itˇs really not easy to fi ...

  6. 4、JPA table主键生成策略(在JPA中table策略是首推!!!)

    用 table 来生成主键详解 它是在不影响性能情况下,通用性最强的 JPA 主键生成器.这种方法生成主键的策略可以适用于任何数据库,不必担心不同数据库不兼容造成的问题. initialValue不起 ...

  7. 写Java程序要体现面向对象

          对于之前写的一篇文章现在想想存在不足之处,之前写的测试ArrayList和LinkedList的各项操作性能比较的程序没有体现面向对象的封装特性,所以,今天把代码重新写了一遍,其实改动的地 ...

  8. 车牌识别LPR(七)-- 字符特征

    第七篇:字符特征 选择的字符特征应该满足以下条件: (1)选取的字符特征具有较强的鲁棒性,不受字符变形.弯曲等影响. (2)两个字符的字符特征不能完全相同,但部分相同是允许的,即选择的字符特征是唯一的 ...

  9. 【C#设计模式——创建型模式】工场方法模式

    工场方法模式对简单工场模式进行了乔庙的扩展,不是用一个专门的类来决定实例化哪一个子类.相反,超类把这种决定延迟到每个子类.这种模式实际上没有决策点,就是没有直接选择一个子类实例化的决策. 看书上的例子 ...

  10. GetKeyState和GetAsyncKeyState以及GetKeyboardState函数的用法与区别

    GetKeyState.GetAsyncKeyState.GetKeyboardState函数的区别: 1.BOOL GetKeyboardState( PBYTE lpKeyState );获得所有 ...