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 ...
随机推荐
- django如何用orm增加manytomany关系字段(自定义表名)
不自定义表名的,网上有现成的,但如果自定义之后,则要变通一下了. app_insert = App.objects.get(name=app_name) site_insert = Site.obje ...
- hdu 1755 A Number Puzzle
这题枚举k节省时间 ;}
- 29. 栈的push,pop序列
题目:给定2个整数序列,其中1个是栈的push顺序,判断另一个有没有可能是对应的pop顺序 解:其实这题主要是判断进栈次数和出栈次数誓不是相等.我是用栈作的,效率不高,每一个元素最多出栈1次,进栈1此 ...
- Android:让EditText不自动获取焦点
解决方法: 在EditText的父级控件中加入属性: android:focusable="true" android:focusableInTouchMode="tru ...
- C++:对象声明
(一)类与对象的关系: c++把类的变量叫做类的对象,对象也称类的实例 (二)对象的定义: 1.在声明类的同时,直接定义对象,即在声明类的右花括号“}”后,直接写出 属于该类的对象名表.例如:clas ...
- 在java程序中访问windows有用户名和密码保护的共享目录
在java程序中访问windows有用户名和密码保护的共享目录 Posted on 2015-11-20 14:03 云自无心水自闲 阅读(3744) 评论(0) 编辑 收藏 --> Jav ...
- 素数筛法--SPOJ Problem 2 Prime Generator
质数(prime number)又称素数,除了1和它本身外,不能整除以其他自然数,换句话说就是该数除了1和它本身以外不再有其他的因数:否则称为合数.最小的质数是2. 要判断一个整数N是不是质数很简单, ...
- 一个小应用的dbcp和c3p0配置实例
以下是一个小应用的数据库连接池配置,包括DBCP和C3P0的配制方法 因为是小应用,完全不涉及访问压力,所以配置上采取尽量节约数据库资源的方式 具体要求如下:初始化连接数为0连接不够,需要新创建时,每 ...
- sudo
sudo的目的:为非根用户授予根用户的权限: 配置文件:/etc/sudoers visudo命令编辑修改/etc/sudoers配置文件 1.一般用户赋权设置: [root@localhost ~] ...
- struct dev_t
device number(dev_t) linux driver 2009-08-21 10:08:03 阅读26 评论0 字号:大中小 dev_t description: the dev ...