用字典树来查询,关键是怎么处理输入的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. POJ 2240 Arbitrage(floyd)

    http://poj.org/problem?id=2240 题意 : 好吧,又是一个换钱的题:套利是利用货币汇率的差异进行的货币转换,例如用1美元购买0.5英镑,1英镑可以购买10法郎,一法郎可以购 ...

  2. SQL server 复习一

    第一天 下面我们从最基础的开始: 在运行里面输入:services.msc 一.启动服务 二.数据库登录的两种身份验证方式 另外一种身份验证方式就是SQL Server身份验证. sa不能使用的时候可 ...

  3. Oracle的学习三:java连接Oracle、事务、内置函数、日期函数、转换函数、系统函数

    1.java程序操作Oracle java连接Oracle JDBC_ODBC桥连接 1.加载驱动: Class.forName("sun.jdbc.odbc.JdbcodbcDriver& ...

  4. Android中数据存储之SharedPreferences

    import android.content.Context; import android.content.SharedPreferences; import android.content.Sha ...

  5. Windows系统上如何使用SSH

    Windows系统上如何使用SSH 传统的网络服务程序如FTP.Telnet等,在网络上一般使用明文传送数据.用户账号和口令信息,容易受到中间人的攻击.用户利用SSH协议后能有效防止DNS及IP欺骗, ...

  6. Wireshark抓包分析HTTPS与HTTP报文的差异

    一.什么是HTTPS: HTTPS(Secure Hypertext Transfer Protocol)安全超文本传输协议 它是一个安全通信通道,它基于HTTP开发,用于在客户计算机和服务器之间交换 ...

  7. 3、JPA一些常用的注解

    常用注解有下面这些: ①:@Entity.@Table.@Id.@GeneratedValue.@Column.@Basic ②:@Transient 用于忽略某个属性,而不对该属性进行持久化操作 ③ ...

  8. Flash上传文件(结合asp.net)

    一.实现原理.在某些场合,我们需要使用Flash进行“文件上传”,原因是Flash 能制作出表现力丰富的UI界面. (自负又孤陋寡闻的我在这里做一个补充:Flash使用flash.net包中的File ...

  9. hive 学习笔记——表的入门操作和命令

    1.受控表(managed table)包括内部表.分区表.桶表: 1.1.分区表 创建分区表: create table banji(id INT,name STRING) partitioned ...

  10. gulp edm测试

    gulp工具的 gulp-mailgun 插件可以将你的html代码,通过mailgun服务器来发送,用于测试,用这个工具发送邮件最适合不过了. 首先我们需要引入gulp和gulp-mailgun模块 ...