ZOJ 3826(字符串hash)
来源:互联网 发布:数据库难不难学 编辑:程序博客网 时间:2024/05/06 09:44
本体的意思是给了一个{ key:value , key:value ..... }的串,且value的形式可以也是这个形式(即是递归的),那么给定一些key1.key2.key3...类似如此的键值查询,让输出对饮键下的value,(没有该键值输出Error!)
example:
输入 :
{"hm":"Edward","stu":{"stu01":"Alice","stu02":"Bob"}}
4
"hm"
"stu"
"stu"."stu01"
"students"
输出为:
"Edward"
{"stu01":"Alice","stu02":"Bob"}
"Alice"
Error!
对于本题目,查了一下,竟然都是对每个链状字符串(把从根key到目标key的所有字符串看做一条链),由于“ : ”最多为10000个,那么意味着最终要保存的hash值也就只有10000条,用hash的话冲突的概率极低,所以大家就妥妥的过了,只不过坑了乖孩子,不敢这么玩的人可就惨了。
#include<iostream>#include<algorithm>#include<cstdio>#include<cmath>#include<cstdlib>#include<cstring>#include <vector>#include <queue>#include <map>#include <string>using namespace std;#define ls (rt<<1)#define rs (ls|1)#define fst first#define snd second#define lson l,mid,ls#define rson mid+1,r,rs#define rep(i,n) for(int i=0;i<(int)n;i++)#define rep1(i,x,y) for(int i=x;i<=(int)y;i++)#define clr(a, x) memset(a, x, sizeof a)typedef long long LL;typedef long long ll;typedef pair<int,int> pii;const int N = 1010101;const int BASE = 131;inline int id(char c){return ((int)c)%(BASE); }int p;char str[N],src[N];map<LL,pii> M;void build(LL pre){ while(str[p]!='}'){ int now = pre; if(str[++p]=='}') return ; while(str[p]!=':'){ now=now*BASE+id(str[p]); p++; } int st = ++p; if(str[p]=='{'){ build(now*BASE+id('.')); } else { while(str[p+1]!=','&&str[p+1]!='}') p++; } M[now]=pii(st,p++); }}int main(){ int T; scanf("%d",&T); while(T--){ M.clear(); scanf("%s",str); p = 0; build(0); int Q; scanf("%d",&Q); while(Q--){ scanf("%s",src); int len = strlen(src),res=0; rep(i,len) res=res*BASE+id(src[i]); if(!M.count(res)) printf("Error!\n"); else { pii te = M[res]; rep1(i,te.first,te.second) printf("%c",str[i]); printf("\n"); } } } return 0;}
0 0
- ZOJ 3826(字符串hash)
- ZOJ 3826 hash+字符串模拟
- [ZOJ 3817 Chinese Knot] 字符串hash+DP
- ZOJ 3817 Chinese Knot (字符串HASH)
- zoj 3533 Gao the String I(伸展树+字符串hash)
- [ZOJ 3807 Just a Palindrome] 字符串hash+二分
- zoj-3826(字符串模拟)
- zoj 1657 hash、、、
- zoj 2672 DP+hash
- zoj Gamblers(hash)
- 字符串hash
- 字符串HASH
- 字符串Hash
- 字符串hash
- 字符串hash
- 字符串hash
- 字符串Hash
- 字符串hash
- 无法原谅自己的退步
- Shiro学习(15)单点登录
- EventBus 《二》 Android EventBus的简单使用
- OC学习 -- NSString NSMutableString NSArray NSMutableArray NSNumber(详解)
- Go 基础之数据类型、变量
- ZOJ 3826(字符串hash)
- 并查集思想+dfs
- Shiro学习(16)综合实例
- js倒计时
- win7中使用xshell连接VMware下ubuntu失败
- opencv vs2013提示缺少Qedit.h问题
- 前端开发工具sublime text 3
- 悬浮的广告是怎么用js设计出来的
- Shiro学习(17)OAuth2集成