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. Java基础知识强化08:将字符串倒序输出(包括空格)的几种方法

    1.最容易想到的估计就是利用String类的toCharArray(),再倒序输出数组的方法了: package himi.hebao05; public class TestDemo02 { pub ...

  2. Objective-C:swift、objective-c、C++、C混合编程

    @import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css); @import url(/ ...

  3. SQL查询显示行号、随机查询、取指定行数据

    转自:walkingp 1.显示行号 如果数据没有删除的情况下主键与行号是一致的,但在删除某些数据,行号就与主键不一致了,这时需要查询行号就需要用新的方法,在SQL Server2005之前,需要使用 ...

  4. CentOS LNMP安装phpMyAdmin

    假设: 已经配置好LNMP环境,并且Nginx的网页目录在/usr/local/nginx/html 1.下载phpMyAdmin wget https://files.phpmyadmin.net/ ...

  5. .NET中TextBox控件设置ReadOnly=true后台取不到值三种解决方法

    当TextBox设置了ReadOnly=true后要是在前台为控件添加了值,后台是取不到的,值为空,多么郁闷的一个问题经过尝试,发现可以通过如下的方式解决这个问题.感兴趣的朋友可以了解下 当TextB ...

  6. mac下开发环境常用操作与命令

    [1] 修改hosts文件 vim /private/etc/hosts

  7. UITapGestureRecognizer会屏蔽掉Button的点击事件( 转载)

    UITapGestureRecognis 前几天在做项目的时候,遇到这个一个问题,在一个视图也就是UIView上添加一个手势,然后又在这个View上添加一个UIButton,然后给按钮添加事件,运行项 ...

  8. Sublime Text 3运行JavaScript控制台

    Node.js是一个基于Chrome JavaScript运行时建立的平台,小巧方便搭建.运行的端口可以在浏览器上运行,显示效果,但每次用浏览器也挺麻烦,我们这里讲的是在sublime text2中配 ...

  9. Linux通配符

    * 任意字符 ?任意单个字符 [] 匹配指定 字符范围内的字符 [^] 指定范围之外的单个字符 常规字符集合 [a-z] a到z的所有小写字母 [A-Z] a到z的所有大写字母 [0-9] 0到9的所 ...

  10. 数据挖掘相关的10个问题[ZZ]

    NO.1 Data Mining 和统计分析有什么不同? 硬要去区分Data Mining和Statistics的差异其实是没有太大意义的.一般将之定义为Data Mining技术的CART.CHAI ...