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.

Sample Input

2
1 2 3 4 5 6
4 3 2 1 6 5

Sample Output

Twin snowflakes found.

题意:给n朵雪花,每个雪花都有6条边,找出是否有两个相同的雪花。
思路:n²遍历肯定不行,然后就想到hash,对于存放hash值的邻接表,我用的是vector,事实证明很慢啊,手写前向星快很多。
hash:我用的是直接相加然后取模一个素数的方法,当然还有很多其他方法,各种异或或者骚运算应该都差不多。 (对于equl函数,我错了很久,之前写的是用while找到一个pos位置和b【0】相同,就退出,然后我发现,找到一个不够,也许有下一个不能直接退出)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std; const int SIZE = ;
int n,tot,p=;
int snow[SIZE][];
vector<int>v[SIZE]; int h(int a)
{
int sum=;
for(int i=;i<;i++)
{
sum = (sum + snow[a][i]) % p;
}
return sum % p;
}; bool equl(int a,int b)
{
for(int j=;j<;j++)
{
if(snow[a][j] != snow[b][])continue;
int flag = ;
for(int i=; i<; i++)
{
if(snow[a][(j + i)%] != snow[b][i] )
flag = ;
}
if(flag)
return ;
flag = ;
for(int i=; i<; i++)
{
if(snow[a][(j-i+)%] != snow[b][i])
flag = ;
}
if(flag) return ;
}
return ;
} bool Insert(int a)
{
int val = h(a);
int len = v[val].size();
for(int i=;i<len;i++)
{ if(equl(v[val][i],a))return ;
}
v[val].push_back(a);
return ;
} int main()
{
scanf("%d",&n);
int flag = ;
for(int i=;i<=n;i++)
{
for(int j=;j<;j++)
{
scanf("%d",&snow[i][j]);
}
if(!flag && Insert(i))
{
puts("Twin snowflakes found.");
flag = ;
}
}
if(!flag)
puts("No two snowflakes are alike.");
}

Snowflake Snow Snowflakes POJ - 3349(hash)的更多相关文章

  1. [poj 3349] Snowflake Snow Snowflakes 解题报告 (hash表)

    题目链接:http://poj.org/problem?id=3349 Description You may have heard that no two snowflakes are alike. ...

  2. Snowflake Snow Snowflakes POJ - 3349 Hash

    题意:一个雪花有六个角  给出N个雪花 判断有没有相同的(可以随意旋转) 参考:https://blog.csdn.net/alongela/article/details/8245005 注意:参考 ...

  3. Snowflake Snow Snowflakes - poj 3349 (hash函数)

    判断n朵雪花中,是否有完全一样的雪花.简单的hash,将雪花的六个边的权值加起来,记为sum,将sum相等的雪花归为一类,再在这里面根据题意找完全相同的,判断顺时针或者逆时针的所有角是否一模一样. # ...

  4. POJ 3349:Snowflake Snow Snowflakes(数的Hash)

    http://poj.org/problem?id=3349 Snowflake Snow Snowflakes Time Limit: 4000MS   Memory Limit: 65536K T ...

  5. POJ 3349 Snowflake Snow Snowflakes (Hash)

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

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

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

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

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

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

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

  9. POJ--3349 Snowflake Snow Snowflakes(数字hash)

    链接:Snowflake Snow Snowflakes 判断所有的雪花里面有没有相同的 每次把雪花每个角的值进行相加和相乘 之后hash #include<iostream> #incl ...

随机推荐

  1. swift 学习- 10 -- 类和结构体

    // '类和结构体' 是人们构建代码所使用的一种通用且灵活的构造体, 我们可以使用完全相同的语法规则来为 '类和结构体' 定义属性 (变量 和 常量) 和添加方法, 从而扩展 类和结构体 的功能 // ...

  2. /etc/rc.d/init.d/iptables: No such file or directory 错误原因

    注:本文转载自cnblogs:一天学点的文章</etc/rc.d/init.d/iptables: No such file or directory 错误原因> RedHat Enter ...

  3. Confluence 6 用户目录图例 - 可读写连接 LDAP

    上面的图:Confluence 连接到一个 LDAP 目录. https://www.cwiki.us/display/CONFLUENCEWIKI/Diagrams+of+Possible+Conf ...

  4. Python1 简介及安装、基础

    Python介绍 Python是面向对象,高级语言,解释,动态和多用途编程语言.Python易于学习,而且功能强大,功能多样的脚本语言使其对应用程序开发具有吸引力. Python的语法和动态类型具有其 ...

  5. linux基础实操四

    实操一: 1)为新加的硬盘分区,一个主分区大小为10剩余空间给扩展分区,在扩展分区上划分2个逻辑分别为5G 2)式化主分区为ext3系统 #mkfs.ext3 /dev/sdb1 3 将逻辑分区设置为 ...

  6. java.text.DateFormat 日期格式化

    一: java.text.DateFormat <%@ page language="java" contentType="text/html; charset=u ...

  7. h5 video标签的使用

     标签的布置 <video src="1.mp4" poster="1.jpg" id="vid" controls> 你的浏览 ...

  8. C++ Primer 笔记——数组

    1.数组的大小是固定不变的,声明时必须指定大小(或者使用列表初始化),而且大小必须大于0,C++ Primer里面也建议,如果不确定元素的个数,请使用vector. ]; , , }; //数组长度固 ...

  9. 插件使用一颜色选择器---cxColor

    cxColor 是一款颜色选择器.这样的插件使用场景不多.可喜的这是国人写的. 官方网站: https://github.com/ciaoca/cxColor 使用方法: 1.引入jquery库 1 ...

  10. 函数sigsuspend

    sigqueue函数原型: 函数作用:新的发送信号系统调用,主要是针对实时信号提出的支持信号带有参数,与函数sigaction()配合使用 int sigqueue(pid_t pid, int si ...