C++-POJ2503-Babelfish[hash]
哈个希加挂个链表
一个要背的字符串hash函数ELFhash()
mod数取数据最大容量的1.5倍最佳?!
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN=;//比1e5大的质数
struct node{char e[],f[];int next;}word[MAXN];
int cnt,hashHead[MAXN];char s[]; int ELFhash(char *key){
unsigned long h=;
for(unsigned long g;*key;h&=~g){
h=(h<<)+(*key++);
g=h&0Xf0000000L;
if(g)h^=g>>;
}
return h%MAXN;
} void find(){
int hash=ELFhash(s);
for(int i=hashHead[hash];i;i=word[i].next)
if(strcmp(s,word[i].f)==)
{printf("%s\n",word[i].e);return;}
printf("eh\n");
} int main() {
for(cnt=;gets(s)&&s[]!='\0';cnt++/*cnt++必须写在外面*/) {
sscanf(s,"%s%s",word[cnt].e,word[cnt].f);
int hash = ELFhash(word[cnt].f);
word[cnt].next=hashHead[hash];//挂表
hashHead[hash]=cnt;
}
while(gets(s))find();
return ;
}
C++-POJ2503-Babelfish[hash]的更多相关文章
- POJ2503——Babelfish(map映射+string字符串)
Babelfish DescriptionYou have just moved from Waterloo to a big city. The people here speak an incom ...
- POJ2503 Babelfish map或者hash_map
POJ2503 这是一道水题,用Map轻松AC. 不过,可以拿来测一下字符串散列, 毕竟,很多情况下map无法解决的映射问题需要用到字符串散列. 自己生成一个质数, 随便搞一下. #include&l ...
- POJ2503(Babelfish)--简单字典树
思路:就是用一个字典树翻译单词的问题,我们用题目中给出的看不懂的那些单词建树,这样到每个单词的叶子结点中存放原来对应的单词就好. 这样查询到某个单词时输出叶子结点存的就行,查不到就"en&q ...
- POJ2503——Babelfish
Description You have just moved from Waterloo to a big city. The people here speak an incomprehensib ...
- POJ2503 Babelfish
题目链接. 分析: 应当用字典树,但stl的map做很简单. #include <iostream> #include <cstdio> #include <cstdli ...
- poj_2503(map映射)
题目链接poj2503 Babelfish Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 38820 Accepted: ...
- POJ2503(hash)
Babelfish Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 41263 Accepted: 17561 Descr ...
- POJ-2503 Babelfish---map或者hash
题目链接: https://vjudge.net/problem/POJ-2503 题目大意: 就像查找一本字典,根据输入的条目和要查询的单词,给出查询结果(每个单词长度不超过10) 解题思路: ma ...
- POJ 2503 Babelfish(map,字典树,快排+二分,hash)
题意:先构造一个词典,然后输入外文单词,输出相应的英语单词. 这道题有4种方法可以做: 1.map 2.字典树 3.快排+二分 4.hash表 参考博客:[解题报告]POJ_2503 字典树,MAP ...
- poj 2503 Babelfish(Map、Hash、字典树)
题目链接:http://poj.org/bbs?problem_id=2503 思路分析: 题目数据数据量为10^5, 为查找问题,使用Hash或Map等查找树可以解决,也可以使用字典树查找. 代码( ...
随机推荐
- Java自学-Lambda 方法引用
Lambda 方法引用 步骤 1 : 引用静态方法 首先为TestLambda添加一个静态方法: public static boolean testHero(Hero h) { return h.h ...
- Jackson使用指南
Jackson常用注解 序列化注解 @JsonAnyGetter 像普通属性一样序列化Map public class ExtendableBean { public String name; pri ...
- P3292 [SCOI2016]幸运数字 [线性基+倍增]
线性基+倍增 // by Isaunoya #include <bits/stdc++.h> using namespace std; #define rep(i, x, y) for ( ...
- VUE动画Javascript钩子不生效问题记录
举例小球动画如下 <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...
- UVA11732(Trie树)
鸣谢https://blog.csdn.net/Baoli1008/article/details/4441936,基本都是抄的代码 #pragma GCC optimize(2) #include ...
- JavaScript 自适应轮播图
代码 话不多说,先上代码,方便复制粘贴.演示 <!DOCTYPE html> <html lang="en"> <head> <meta ...
- 使用Dockerfile构建镜像命令自己的理解
1.FROM 基于那个基础命令开始构建镜像,我的理解就是选择一个操作系统 2.CMD 里面放的是指定一个容器启动时要运行的命令 3.ENTRYPOINT 类似于CDM命令,不过 docker run ...
- mysql 数据库优化的几种方法
1.选取最适用的字段属性 MySQL可以很好的支持大数据量的存取,但是一般说来,数据库中的表越小,在它上面执行的查询也就会越快.因此,在创建表的时候,为了获得更好的性能,我们可以将表中字段的宽度设得尽 ...
- 使用ResXmanager实现多语言[转]
1 多國語系 - 使用RESXMANAGER管理資源檔 1.1 前言 在實作多國語系網站時,針對靜態文字多會使用資源檔(Resource)來對應出各語系所需顯示的內容.由於資源檔可能會依照特定結構放式 ...
- 重新机兵回归(MMR)
重新机兵回归记录 S/L法 Save / Load 法 . 在关键战斗前,先save一把 , 在结算奖励后如果奖励不好 , 再重新load再来过 . 比如说拿红牡丹等 . 还可以在逃跑时用此法 . 随 ...