【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 ...
随机推荐
- PHP图像函数
(1)常见的验证码哪些? 图像类型.语音类型.视频类型.短信类型等 (2)使用验证码的好处在哪里? ①防止恶意的破解密码如一些黑客为了获取到用户信息,通过不同的手段向服务器发送数据,验证猜测用户信 ...
- 浅谈AC自动机模板
什么是AC自动机? 百度百科 Aho-Corasick automaton,该算法在1975年产生于贝尔实验室,是著名的多模匹配算法. 要学会AC自动机,我们必须知道什么是Trie,也就是字典树.Tr ...
- Java垃圾回收简介
Java关键术语 JavaAPI:一系列帮助开发者创建Java应用程序的封装好的库. Java 开发工具包 (JDK):一系列工具帮助开发者创建Java应用程序.JDK包含工具编译.运行.打包.分发和 ...
- Linux学习笔记记录(四)
- Django DTL模板语法中的过滤器
template_filter_demo 过滤器相关: 一.形式:小写{{ name | lower }} 二.串联:先转义文本到HTML,再转换每行到 <p> 标签{{ my_text| ...
- open random
open文件操作 f = open('文件路径',mode='rwab+',encoding='utf-8') # content = f.read(3) # 读出来的都是字符 # f.seek(3) ...
- 如何卸载 win10 自带的“电影和电视”软件
参考这里: https://answers.microsoft.com/zh-hans/windows/forum/apps_windows_10-movies/win10%E7%9A%84%E7%9 ...
- Java基础学习总结(85)——Java中四种线程安全的单例模式实现方式
- hdu 3062 2-sat
#include<stdio.h> #include<string.h> #define N 2100 struct node { int u,v,next; }bian[N* ...
- vue.js定义一个一级的路由 ----由浅入深
#### 定义一个路由- 实例化一个路由并设置路由映射表 - 实例化里面第一个参数 routes 路由映射表 - routes 里面参数 - path 路由的路径 - component 路由对应的组 ...