POJ3349【手写Hash】
来源:互联网 发布:南风知我意免费阅读 编辑:程序博客网 时间:2024/05/22 09:45
基础题。
利用邻接表,价值hash值为数组head[]的下标,然后在该链下寻找。
//#include <bits/stdc++.h>#include<iostream>#include<cstdio>#include<cstring>#include<string.h>#include<queue>#include<cmath>#include<algorithm>using namespace std;typedef pair<int,int>PII;typedef long long LL;const int N = 1e5 + 10;const int mod = 1e5 + 7;struct asd{ int x[6]; int nex;}node[N];int head[N], Size;bool flag;void init(){ memset(head, -1, sizeof(head)); Size = 0;}int GetHashV(int num[]){ int sum = 0; for(int i=0;i<6;i++) sum += sum + num[i]; return sum%mod;}bool Compare(int a[], int b[]){ for(int i=0;i<6;i++) if(a[i] != b[i]) return false; return true;}void Add(int num[]){ LL pos = GetHashV(num); for(int i = head[pos];~i;i=node[i].nex){ if(Compare(node[i].x, num)) { flag = true; return; } } for(int i=0;i<6;i++) node[Size].x[i] = num[i]; node[Size].nex = head[pos]; head[pos] = Size++;}int main(){ int n, val[6]; init(); scanf("%d",&n); flag = false; while(n--){ for(int i=0;i<6;i++) scanf("%d",&val[i]); if(flag) continue; sort(val,val+6); Add(val); } if(flag)printf("Twin snowflakes found.\n"); else printf("No two snowflakes are alike.\n"); return 0;}
阅读全文
0 0
- POJ3349【手写Hash】
- poj3349-hash
- poj3349--Hash
- poj3349(Hash)
- POJ3349 HASH
- Hash练习题:【POJ3349】
- poj3349(hash)
- poj3349(数字hash)
- POJ3349 Snowflake Snow Snowflakes(hash)
- POJ3349 Snowflake Snow Snowflakes(hash)
- poj3349--Snowflake Snow Snowflakes(hash)
- poj3349 Snowflake Snow Snowflakes之hash入门
- POJ3349总结(第一次用hash解决问题)
- POJ3349-Snowflake Snow Snowflakes(hash表)
- poj3349
- poj3349
- POJ3349
- POJ3349
- Web自动化之Headless Chrome编码实战
- Java Web 之 Serlvet
- 学习总结——JAVA的编码
- 在阿里云ECS装的postgresql远程连接不了的问题
- ES6 箭头函数用法和案例
- POJ3349【手写Hash】
- AJAX 概念 优势 发展前景 工作原理 底层技术 状态 缺点 框架
- コンピュターグラフィックス COMPUTER GRAPHICS[FOR CG ENGINEERS]-Chapter4-0707
- android Universal-Image-Loader 使用及解析
- Docker-构建私有仓库Registry
- 跟我学SpringMVC
- NSA的第七种武器|双脉冲星(DoublePulsar) 后门详细分析
- 一封伪造邮件引发的“探索”(涉及钓鱼邮件、SPF和DKIM等)
- OOB(out of band)分析系列之DNS渗漏