【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 ...
随机推荐
- 05网页<div></div>块内容
网页<div></div>块内容 <header>此处为新 header 标签的内容</header> <navigation>此处为新 n ...
- linux shell学习笔记二---自定义函数(定义、返回值、变量作用域)介绍
linux shell 可以用户定义函数,然后在shell脚本中可以随便调用.下面说说它的定义方法,以及调用需要注意那些事项. 一.定义shell函数(define function) 语法: [ f ...
- Python学习-字符串的基本知识
字符串的基本知识 根据所展示形式的不同,字符串也可以分为两类 原始字符串: 使用单引号包括:‘liuwen’ 使用双引号包括:"liuwen" 使用3个单引号包括 :'''liuw ...
- 关于Linux字符集的查看及修改
一·查看字符集 字符集在系统中体现形式是一个环境变量,其查看当前终端使用字符集的方式可以有以下几种方式: 1.[root@ ~]# echo $LANG en_US.UTF-8 ...
- Diango REST framework 视图继承图
- 制作一个最小Linux系统
使用的是itop4412开发板(仅记录个人的学习回顾,如有不当之处欢迎指出) ---------致谢 准备:busybox软件.uboot(一般和开发板配套).zImage(kernel内核).ram ...
- 关于vuex自己理解的三幅图
- mysql 查询当天、本周,本月,上一个月的数据---https://www.cnblogs.com/benefitworld/p/5832897.html
mysql 查询当天.本周,本月,上一个月的数据 今天 select * from 表名 where to_days(时间字段名) = to_days(now()); 昨天 SELECT * FROM ...
- 关于 Neo4j 属性个数的限制
关于 Neo4j 属性个数的限制 目前累积统计它有34.4亿个节点,344亿的关系,和6870亿条属性. 社区版,Neo4j对 数据库内 节点.关系 上的属性名个数是有限制的.数据库中至多存在687亿 ...
- java多线程编程核心技术(一)--多线程技能
1.进程和线程的概念 1.进程:进程是操作系统的基础,是一次程序的执行,是一个程序及其数据在处理机上顺序执行时所发生的活动,是程序在一个数据集合上运行的过程,他是系统进行资源分配和调度的一个独立单位. ...