【POJ 3349】 Snowflake Snow Snowflakes
【题目链接】
http://poj.org/problem?id=3349
【算法】
哈希
若两片雪花相同,则它们六个角上的和一定相同,不妨令 H(A) = sigma(Ai) % P ,每次只要到哈希表里查是否出现相同雪花,即可
【代码】
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std;
#define MAXN 100010
const int P = 1e5 + ; int i,j,n,tot;
int a[],Head[P],nxt[MAXN],snow[MAXN][]; inline int get()
{
int i,ret = ;
for (i = ; i <= ; i++) ret = (ret + a[i]) % P;
return ret;
}
inline bool Insert()
{
int i;
int Hash = get();
bool same;
for (i = Head[Hash]; i; i = nxt[i])
{
same = true;
for (j = ; j <= ; j++) same &= (snow[i][j] == a[j]);
if (same) return true;
}
tot++;
nxt[tot] = Head[Hash];
for (i = ; i <= ; i++) snow[tot][i] = a[i];
Head[Hash] = tot;
return false;
} int main()
{ scanf("%d",&n);
for (i = ; i <= n; i++)
{
for (j = ; j <= ; j++) scanf("%d",&a[j]);
sort(a+,a+);
if (Insert())
{
printf("Twin snowflakes found.\n");
return ;
}
}
printf("No two snowflakes are alike.\n"); return ; }
【POJ 3349】 Snowflake Snow Snowflakes的更多相关文章
- POJ 3349:Snowflake Snow Snowflakes(数的Hash)
http://poj.org/problem?id=3349 Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K T ...
- POJ 3349:Snowflake Snow Snowflakes 六片雪花找相同的 哈希
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 35642 Accep ...
- 哈希—— POJ 3349 Snowflake Snow Snowflakes
相应POJ题目:点击打开链接 Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions ...
- POJ 3349 Snowflake Snow Snowflakes(简单哈希)
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 39324 Accep ...
- poj 3349:Snowflake Snow Snowflakes(哈希查找,求和取余法+拉链法)
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 30529 Accep ...
- POJ 3349 Snowflake Snow Snowflakes
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 27598 Accepted: ...
- POJ 3349 Snowflake Snow Snowflakes (Hash)
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 48646 Accep ...
- [ACM] POJ 3349 Snowflake Snow Snowflakes(哈希查找,链式解决冲突)
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 30512 Accep ...
- poj3349 Snowflake Snow Snowflakes【HASH】
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 49991 Accep ...
随机推荐
- Listview异步加载图片之优化篇
在APP应用中,listview的异步加载图片方式能够带来很好的用户体验,同时也是考量程序性能的一个重要指标.关于listview的异步加载,网上其实很多示例了,中心思想都差不多,不过很多版本或是有b ...
- 前k大金币(动态规划,递推)
/* ///题解写的很认真,如果您觉得还行的话可以顶一下或者评论一下吗? 思路: 这题复杂在要取前k大的结果,如果只是取最大情况下的金币和,直接 动态规划递归就可以,可是前k大并不能找出什么公式,所以 ...
- CodeForces 【20C】Dijkstra?
解题思路 heap+Dijkstra就能过.注意边是双向边,要用long long. 附上代码 #include <iostream> #include <queue> #in ...
- poj3061 Subsequence【尺取法】
Description A sequence of N positive integers (10 < N < 100 000), each of them less than or eq ...
- Linux学习笔记记录(五)
- Python学习第二阶段day1 内置函数,序列化,软件目录开发规范
内置函数 1.abs() 求绝对值 2.all() 所有元素为真才返回真 all( [1,1,2,3,-1] ) 值为True 3.any() 所有元素为假才返回假 any([0,0,0 ...
- RequestMapping_HiddenHttpMethodFilter 过滤器
[REST] 1.REST:即Representational State Transfer.(资源)表现层状态转化.是目前最流行的一种互联网软件架构.它结构清晰.符合标准.易于理解.扩展方便,所以得 ...
- Leetcode 133.克隆图
克隆图 克隆一张无向图,图中的每个节点包含一个 label (标签)和一个 neighbors (邻接点)列表 . OJ的无向图序列化: 节点被唯一标记. 我们用 # 作为每个节点的分隔符,用 , 作 ...
- git巧妙命令行
git cherry-pick c7081607cfd1bfa99b6e6c70c208e71fbd8767ae
- STL源码剖析 学习笔记 MiniSTL
https://github.com/joeyleeeeeee97 目录: 第二章 空间适配器 第三章 迭代器 第四章 序列式容器(vector,list,deque,stack,heap,prior ...