题目链接:http://poj.org/problem?id=3349

Description

You may have heard that no two snowflakes are alike. Your task is to write a program to determine whether this is really true. Your program will read information about a collection of snowflakes, and search for a pair that may be identical. Each snowflake has six arms. For each snowflake, your program will be provided with a measurement of the length of each of the six arms. Any pair of snowflakes which have the same lengths of corresponding arms should be flagged by your program as possibly identical.

Input

The first line of input will contain a single integer n, 0 < n ≤ 100000, the number of snowflakes to follow. This will be followed by n lines, each describing a snowflake. Each snowflake will be described by a line containing six integers (each integer is at least 0 and less than 10000000), the lengths of the arms of the snow ake. The lengths of the arms will be given in order around the snowflake (either clockwise or counterclockwise), but they may begin with any of the six arms. For example, the same snowflake could be described as 1 2 3 4 5 6 or 4 3 2 1 6 5.

Output

If all of the snowflakes are distinct, your program should print the message:
No two snowflakes are alike.
If there is a pair of possibly identical snow akes, your program should print the message:
Twin snowflakes found.

题目大意:

给出n个长度为6的圆,问你是否存在两个圆是一样的

题解:

考虑到n的取值范围,直接比较果断的TLE
那么我们考虑先把每个数列hash,然后建立hash表,对于hash值相同的元素在当前的链表里暴力比较就好了
构造$hash(a_1,a_2...a_6)=\sum_{i=1}^{6}a_i+\prod_{i=1}^{6}a_i$
 
AC代码
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<iostream> const int N=1e5+;
const int P=1e5+;
int n,tot;
int head[N],snow[N][],next[N];
int H(int *a)
{
int sum=,re=;
for (int i=;i<;i++)
{
sum=(sum+a[i])%P;
re=1ll*re*a[i]%P;
}
return (sum+re)%P;
}
bool equal(int *a,int *b)
{
for (int i=;i<;i++)
for (int j=;j<;j++)
{
bool flag=true;
for (int k=;k<;k++) if (a[(i+k)%]!=b[(j+k)%]) flag=false;
if (flag) return true;
flag=true;
for (int k=;k<;k++) if (a[(i+k)%]!=b[(j-k+)%]) flag=false;
if (flag) return true;
}
return false;
}
bool insert(int *a)
{
int val=H(a);
for (int i=head[val];i;i=next[i])
{
if (equal(snow[i],a)) return true;
}
++tot;
for (int i=;i<;i++) snow[tot][i]=a[i];
next[tot]=head[val];
head[val]=tot;
return false;
}
int main()
{
int a[];
scanf("%d",&n);
for (int i=;i<=n;i++)
{
for (int j=;j<;j++) scanf("%d",a+j);
if (insert(a))
{
puts("Twin snowflakes found.");
return ;
}
}
puts("No two snowflakes are alike.");
return ;
}

[poj 3349] Snowflake Snow Snowflakes 解题报告 (hash表)的更多相关文章

  1. POJ 3349 Snowflake Snow Snowflakes(哈希表)

    题意:判断有没有两朵相同的雪花.每朵雪花有六瓣,比较花瓣长度的方法看是否是一样的,如果对应的arms有相同的长度说明是一样的.给出n朵,只要有两朵是一样的就输出有Twin snowflakes fou ...

  2. POJ 3349 Snowflake Snow Snowflakes (哈希表)

    题意:每片雪花有六瓣,给出n片雪花,六瓣花瓣的长度按顺时针或逆时针给出,判断其中有没有相同的雪花(六瓣花瓣的长度相同) 思路:如果直接遍历会超时,我试过.这里要用哈希表,哈希表的关键码key用六瓣花瓣 ...

  3. POJ 3349 Snowflake Snow Snowflakes (Hash)

    Snowflake Snow Snowflakes Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 48646   Accep ...

  4. [ACM] POJ 3349 Snowflake Snow Snowflakes(哈希查找,链式解决冲突)

    Snowflake Snow Snowflakes Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 30512   Accep ...

  5. 哈希—— POJ 3349 Snowflake Snow Snowflakes

    相应POJ题目:点击打开链接 Snowflake Snow Snowflakes Time Limit: 4000MS   Memory Limit: 65536K Total Submissions ...

  6. POJ 3349 Snowflake Snow Snowflakes(简单哈希)

    Snowflake Snow Snowflakes Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 39324   Accep ...

  7. POJ 3349 Snowflake Snow Snowflakes

    Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 27598 Accepted: ...

  8. poj 3349:Snowflake Snow Snowflakes(哈希查找,求和取余法+拉链法)

    Snowflake Snow Snowflakes Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 30529   Accep ...

  9. hash应用以及vector的使用简介:POJ 3349 Snowflake Snow Snowflakes

    今天学的hash.说实话还没怎么搞懂,明天有时间把知识点总结写了,今天就小小的写个结题报告吧! 题意: 在n (n<100000)个雪花中判断是否存在两片完全相同的雪花,每片雪花有6个角,每个角 ...

随机推荐

  1. 再续iOS开发中的这些权限

    前言 上篇文章iOS开发中的这些权限,你搞懂了吗?介绍了一些常用权限的获取和请求方法,知道这些方法的使用基本上可以搞定大部分应用的权限访问的需求.但是,这些方法并不全面,不能涵盖住所有权限访问的方法. ...

  2. Java IO 基础

    早上复习了IO.NIO.AIO相关的概念,将其中一些要点记录一下. 从编程语言层面 BIO | NIO | AIO 以Java的角度,理解,linux c里也有AIO的概念(库),这些概念不知道什么原 ...

  3. 8.MATLAB数据分析

    概述: clc; clear all; p1=[ ]; y=poly2sym(p1) %由向量创建多项式 disp(y) %显示多项式 1 多项式的求值与求根 clc; clear all; p=[ ...

  4. 【转】Docker基础

    一.简介 Docker是一个开源的应用容器引擎,使用Go语言开发,基于Linux内核的CGroup.Namespace.Union FS等技术实现的一种系统级虚拟化技术. 特性 更高效的利用系统资源: ...

  5. 求包含每个有序数组(共k个)至少一个元素的最小区间

    title: 求包含每个有序数组(共k个)至少一个元素的最小区间 toc: false date: 2018-09-22 21:03:22 categories: OJ tags: 归并 给定k个有序 ...

  6. 比较不错的spring学习博客

    http://blog.csdn.net/tangl_99/article/details/1176141

  7. TimSort学习资料

    深入理解 timsort 算法(1):自适应归并排序 如何找出Timsort算法和玉兔月球车中的Bug? Java TimSort算法 源码 笔记 Timsort https://en.wikiped ...

  8. SqlServer数据库字典

    网上有很多SQL Server数据库字典的SQL语句,七零八落,我在工作整理了一下思路,总结SQL代码如下.数据库字典包括表结构(分2K和2005).索引和主键. 外键.约束.视图.函数.存储过程.触 ...

  9. SQL Server 汉字转拼音字母

    /* 汉字转拼音首字母 */ create function fun_getPY(@str nvarchar(4000)) returns nvarchar(4000) as begin declar ...

  10. 【转】JS回调函数--简单易懂有实例

    JS回调函数--简单易懂有实例 初学js的时候,被回调函数搞得很晕,现在回过头来总结一下什么是回调函数. 我们先来看看回调的英文定义:A callback is a function that is ...