Time Limit: 4000MS   Memory Limit: 65536K
Total Submissions: 27277   Accepted: 7197

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.

Sample Input

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

Sample Output

Twin snowflakes found.
题意:给n个序列,每个序列有六个数字,每个数字的取值范围是[0,10000000],如果n个序列中有任意两个顺时针或逆时针读是一样的就输出Twin snowflakes found.如果任意两个都不同就输出No two snowflakes are alike. 解题思路:将每个序列的六个数的和对大素数取模后存在邻接表中,这样就缩小了可比较序列的范围,只有存在同一个邻接表的两个序列才有可能匹配;
 #include<stdio.h>
#include<string.h>
#include<vector>
using namespace std; struct node
{
int sum,id;
};
vector<struct node>head[];
const int p = ;
int a[][]; bool clockwise(int x, int y)//顺时针判断
{
int i,j;
for(i = ; i < ; i++)
{
if(a[x][i] == a[y][])
{
for(j = ; j < ; j++)
if(a[x][(i+j)%] != a[y][j])
break;
if(j >= ) return true;
}
}
return false;
}
bool counterclockwise(int x, int y)//逆时针判断
{
int i,j;
for(i = ; i < ; i++)
{
if(a[x][i] == a[y][])
{
for(j = ; j < ; j++)
if(a[x][(i+j)%] != a[y][-j])
break;
if(j >= ) return true;
}
}
return false;
}
int main()
{
int i,j,n,tmp;
for(i = ; i < ; i++)
head[i].clear();
scanf("%d",&n);
int ok = ;
for(i = ; i < n; i++)
{
int sum = ;
for(j = ; j < ; j++)
{
scanf("%d",&a[i][j]);
sum += a[i][j];
}
tmp = sum%p;//对大素数取模
if(!ok)
{
for(j = ; j < head[tmp].size(); j++)
{
if(head[tmp][j].sum == sum &&(clockwise(head[tmp][j].id,i)||counterclockwise(head[tmp][j].id,i)))
{
ok = ;
break;
}
}
if(ok == ) head[tmp].push_back((struct node){sum,i});
}
}
if(ok == ) printf("Twin snowflakes found.\n");
else printf("No two snowflakes are alike.\n");
return ;
}

 

Snowflake Snow Snowflakes(哈希,大素数取模)的更多相关文章

  1. POJ3349 Snowflake Snow Snowflakes(哈希)

    题目链接. 分析: 哈希竟然能这么用.检查两片雪花是否相同不难,但如果是直接暴力,定会超时.所以要求哈希值相同时再检查. AC代码: #include <iostream> #includ ...

  2. poj3349 Snowflake Snow Snowflakes —— 哈希表

    题目链接:http://poj.org/problem?id=3349 题意:雪花有6个瓣,有n个雪花,输入每个雪花的瓣长,判断是否有一模一样的雪花(通过旋转或翻转最终一样,即瓣长对应相等).如果前面 ...

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

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

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

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

  5. 哈希-Snowflake Snow Snowflakes 分类: POJ 哈希 2015-08-06 20:53 2人阅读 评论(0) 收藏

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

  6. 哈希—— POJ 3349 Snowflake Snow Snowflakes

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

  7. Snowflake Snow Snowflakes(哈希表的应用)

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

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

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

  9. POJ 3349:Snowflake Snow Snowflakes 六片雪花找相同的 哈希

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

随机推荐

  1. WWDC-UIKit 中协议与值类型编程实战

    本文为 WWDC 2016 Session 419 的部分内容笔记.强烈推荐观看. 设计师来需求了 在我们的 App 中,通常需要自定义一些视图.例如下图: 我们可能会在很多地方用到右边为内容,左边有 ...

  2. Java基础知识强化03:Java中的堆与栈

    1.在JVM中,内存分为两个部分,Stack(栈)和Heap(堆),这里,我们从JVM的内存管理原理的角度来认识Stack和Heap,并通过这些原理认清Java中静态方法和静态属性的问题. 一般,JV ...

  3. Java使用poi对Execl简单_写_操作

    public class WriteExecl { @Test public void writeExeclTest() throws Exception{ OutputStream os = new ...

  4. android如何获取手机型号和版本号

    public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView ...

  5. ArrayList 类和List<T>泛型类

    ArrayList集合类在System.Colletions命名空间下,它其实是一个特殊的数组,它可以动态的添加和删除元素,根据元素的改变自动决定它自身的大小,也可以灵活的插入元素等操作,使用起来要比 ...

  6. 关于ASP.NET控件方面的学习(恢复版)

    前段时间没有把学习中的遇到的问题和解决方法详细总结,今天整理整理.. 鉴于我们这个研究生论文管理系统是小组形式,所以说虽然我只负责数据库,但是其它部分也多少有些工作方面的涉及,最后感谢各位同学和老师的 ...

  7. 最终版-perl工具解析数据库的报告文件0120

    ********************需要根据自己的实际环境修改哦**************************** ******************** 1. 收集awr报告样本   a ...

  8. KAFKA分布式消息系统[转]

    KAFKA分布式消息系统  转自:http://blog.chinaunix.net/uid-20196318-id-2420884.html Kafka[1]是linkedin用于日志处理的分布式消 ...

  9. iframe的缺点与优点?

    iframe是一种框架,也是一种很常见的网页嵌入方式. iframe的优点: iframe能够原封不动的把嵌入的网页展现出来. 如果有多个网页引用iframe,那么你只需要修改iframe的内容,就可 ...

  10. Linux下JDK环境变量配置

    JDK官方下载地址: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 我的下载路 ...