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. js数组的实例方法sort() 排序方法的运用,不再只是.sort()

    1, sort() 不传回调函数的话,默认按照字母顺序(字符编码)的顺序进行排序. 2, sort() 通过传回调函数来控制从小到大的排序还是从大到小的排序: var arr = [1,23,5,6, ...

  2. gnuradio 初次使用

    参考链接: 入门 http://www.cnblogs.com/moon1992/p/5739027.html 创建模块 http://www.cnblogs.com/moon1992/p/54246 ...

  3. WPA-PSK无线网络密码破解原理

    1.基于WPA2的加密标准还是能够被破解,一个弊端是他无法避开时候双方验证的模式来认证取得合法性的连接,当我们抓取足够多得双反认证的数据包之后就可以破解密码.之前很多片的博客写了如何破解这种加密的秘钥 ...

  4. java接口实现

    1.接口中的方法一定是public abstract方法所以类要继承实现接口的时候,一定要去掉abstract修饰符,而且还要标明方法的访问权限一定是public 声明接口不适用public就是友好的 ...

  5. PyCharm设置字体风格

    设置字体风格:File—Setting—Editor-Color Scheme-Color Scheme Font-把Scheme设置为:WarmNeon

  6. php安装扩展

    php安装扩展 以前以为php的扩展要重新编译php,今天在群友的指点下知道可以像apache模块一样动态扩展,以mcrypt举例. 进入要安装的扩展的源码目录cd /root/php-5.2.6/e ...

  7. 步步为营-104-Lambda语句

    1:Lambda的拼接 首先借助一个Lambda的帮助类 using System; using System.Collections.Generic; using System.Linq; usin ...

  8. Java+selenium之WebDriver常见特殊情况如iframe/弹窗处理(四)

    1. iframe 的处理 查找元素必须在对应的 ifarme 中查找,否则是找不到的 // 传入参数为 frame 的序号,从0开始 driver.switchTo().frame(Int inde ...

  9. IEDA序列化设置

  10. ZOJ 4057 XOR Clique(位运算)

    XOR Clique BaoBao has a sequence a​1​,a​2,...,a​n. He would like to find a subset S of {1,2,...,n} s ...