字符串哈希初步 洛谷3370
来源:互联网 发布:淘宝售后服务管理 编辑:程序博客网 时间:2024/04/29 01:59
跑得好慢QAQ
#include<cstdio>#include<cctype>#include<cstring>using namespace std;inline void read(int &x){ x = 0; int flag = 1; char c; while(! isgraph(c = getchar())) if(c == '-') c = getchar(); while(isgraph(c)) x = x * 10 + c - '0', c = getchar(); x *= flag;}inline void read(char *s){ char c; while(! isgraph(c = getchar())); int top = 0; while(isgraph(c)) *(s + (top ++)) = c, c = getchar();}const int MAXN = 1 << 14;const int MAXLEN = 1 << 11;int top;int head[1 << 20];int hash(char *s){ int len = strlen(s); unsigned int h = 0; for(int i = 0; i < len; i ++) h = h * 31 + *(s + i); return h & 0x7fffffff;}struct Table{ char s[MAXLEN]; int next;}table[MAXN];void print(int x){ if(x == 0) putchar('0'); int ans[1 << 4], top = 0; while(x) ans[top ++] = x % 10, x /= 10; for(; top; top --) putchar(ans[top - 1] + '0'); putchar('\n');}int main(){ int n; read(n); int top = 0; memset(head, - 1, sizeof(head)); int ans = 0; char s[MAXLEN]; memset(s, 0, sizeof(s)); for(int i = 0; i < n; i ++) { read(s); int len = strlen(s);// int ha = hash(s) % (1 << 20); int ha = 1; int j = head[ha]; while(1) { if(j == - 1) { for(int k = 0; k < len; k ++) table[top].s[k] = s[k]; table[top].next = head[ha]; head[ha] = top ++; ans ++; break; } else if (len == strlen(table[j].s)) { int flag = 1; for(int k = 0; k < len; k ++) if(table[j].s[k] != s[k]) flag = 0; if(flag) break; } j = table[j].next; } for(int i = 0; i < len; i ++) s[i] = 0; } print(ans);}
0 0
- 字符串哈希初步 洛谷3370
- 汇编程序初步,显示字符串
- 学习笔记---字符串初步
- 洛谷3370 字符串哈希
- 1125 集合(哈希初步学)
- HTML5 Canvas 初步:字符串,路径,背景,图片
- 正则表达式初步_分散字符串
- 2.1 Swift字符和字符串初步
- 对字符串复制的初步认识
- 洛谷3370字符串哈希模板
- 初步
- Java学习笔记:字符串与类的初步
- 第02讲-正则表达式初步_分散字符串
- 第13周项目5--字符串复制的初步体验
- RY哥查字典(字符串双模hash初步)
- FZU 2137 奇异字符串 字符串哈希
- 洛谷 P3370 【模板】字符串哈希
- 【模板】【洛谷P3370】字符串哈希
- Android----MVC、MVP、MVVM、区别介绍
- 咱们聊聊【DOM】吧
- 微信淘宝客实战经验分享
- C# 队列(Queue)和 堆栈(Stack)
- 15款顶级的开源人工智能工具推荐
- 字符串哈希初步 洛谷3370
- 离职前最后7天的学习计划
- Linux流量控制工具TC
- 随机森林基本原理
- Oracle 11G oem 配置及问题解决
- 知名搜索引擎Elasticsearch成为勒索软件敲诈目标
- 初识Hook技术
- Android Studio系列教程六--Gradle多渠道打包
- XUtils3框架的基本使用方法