UVALive 5029
用字典树来查询,关键是怎么处理输入的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的更多相关文章
- UVALive 5029 字典树
E - Encoded Barcodes Crawling in process...Crawling failedTime Limit:3000MS Memory Limit:0KB 6 ...
- UVALive - 4108 SKYLINE[线段树]
UVALive - 4108 SKYLINE Time Limit: 3000MS 64bit IO Format: %lld & %llu Submit Status uDebug ...
- UVALive - 3942 Remember the Word[树状数组]
UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...
- UVALive - 3942 Remember the Word[Trie DP]
UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...
- 思维 UVALive 3708 Graveyard
题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...
- UVALive 6145 Version Controlled IDE(可持久化treap、rope)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- 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 ...
- UVALive 6508 Permutation Graphs
Permutation Graphs Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit ...
- UVALive 6500 Boxes
Boxes Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Pract ...
随机推荐
- Java 反编译工具几枚(class转java)
1.Java Decompiler Yet another fast Java decompiler. 下载地址:http://jd.benow.ca/#jd-gui-download 一款非常简洁的 ...
- linux shell 命令学习(1) du- estimate file space usage
du - estimate file space usage , 计算文件的磁盘大小 语法格式: du [OPTION] ... [FILE] 描述: 汇总每个文件的磁盘大小, 递归汇总目录的大小, ...
- Java API —— 泛型
1.泛型概述及使用 JDK1.5以后出现的机制 泛型是一种特殊的类型,它把指定类型的工作推迟到客户端代码声明并实例化类或方法的时候进行.也被称为参数化类型,可以把类型当作参数一样传递过来,在传递过来之 ...
- HDU 4351 Digital root 线段树区间合并
依然不是十分理解……待考虑…… #include <cstdio> #include <cstring> #include <cstdlib> #include & ...
- .Net MVC API初试
新建.net mvc api项目后,直接运行,默认会访问http://localhost:xxxx/Home/Index页面,这个页面不是要访问的API页面. 从项目的目录可以看出,默认的API页面访 ...
- 今天晚上 中国互联网被Struts2漏洞血洗
Apache官方今天晚上发布安全公告(官方编号S2-032/CVE编号CVE-2016-3081),Apache Struts2服务在开启动态方法调用(DMI)的情况下,可以被远程执行任意命令,安全威 ...
- mac下装Ruby
https://ruby-china.org/wiki/install_ruby_guide
- 点(Dot)与像素(Pixel)的区别
DPI中的点(Dot)与图像分辨率中的像素(Pixel)是容易混淆的两个概念, DPI中的点可以说是硬件设备最小的显示单元, 而像素则既可是一个点,又可是多个点的集合.在扫描仪扫描图像时,扫描仪的每一 ...
- VS2012 professional和VS2012 Ultimate的区别
http://www.c-sharpcorner.com/news/1750/visual-studio-2012-editions-comparison.aspx http://karthikdod ...
- SetCapture、ReleaseCapture、GetCapture
正常情况下,鼠标指针位于哪个窗口区域内,鼠标消息就自动发给哪个窗口.如果调用了SetCapture,之后无论鼠标的位置在哪,鼠标消息都发给指定的这个窗口,直到调用ReleaseCapture或者调用S ...