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文件处理工具类

    import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.BufferedRead ...

  2. 样式单位之px、em、rem

    最近在看bootstrap.css的时候看到很多单位都用到rem而不是熟系的px.经学习得知: 1.px精确的单位: 2.em为相对单位(相对父级元素) 3.rem为相对单位(相对根元素 html)

  3. JS中的事件绑定,事件捕获,事件冒泡以及事件委托,兼容IE

    转载请注明出处:http://www.cnblogs.com/zhangmingze/p/4864367.html   ● 事件分为三个阶段:   事件捕获 -->  事件目标 -->   ...

  4. Active Desktop--桌面字体背景被修改

    怎么修改回来 步骤如下 方法一.在桌面上点击右键 -- 排列图标 -- 去掉“在桌面上锁定Web项目”上的勾. 方法二.右键点击我的电脑 -- 属性 -- 高级 -- 点击“性能”下面的“设置”按钮, ...

  5. discuz论坛几种安全策略(一)

    安全问题 最近公司准备搭建一个discuz论坛,大头让我调研一下discuz的安全策略,并提出如下几点要求: 1.防止php上传漏洞2.防止大量刷新攻击限制某个IP大量刷新某一页面导致论坛宕机3.防止 ...

  6. Direct 2D实现界面库 (2)

    Direct 2D实现界面库 (1) http://www.cnblogs.com/mmc1206x/p/3924580.html 上篇说完了每个 LNode 的绘制过程. 也就是 onDraw 的实 ...

  7. 第17章课后题(高级Perl技巧)

    17.1 写一个程序,从文件中读取一组字符串(每行一个),然后让用户键入模式以便进行字符串匹配. 对于每个模式,程序应该说明文件里共有多少字符串匹配成功,分别是哪些字符串. 对于所键入的每个新模式,不 ...

  8. clipboard.js IE下 不允许复制时, 问题修改

    问题描述:https://github.com/zenorocha/clipboard.js/wiki/Known-IssuesOn IE9-11 there's a prompt that asks ...

  9. delegate 中的BeginInvoke和EndInvoke方法

    开发语言:C#3.0 IDE:Visual Studio 2008 一.C#线程概述 在操作系统中一个进程至少要包含一个线程,然后,在某些时候需要在同一个进程中同时执行多项任务,或是为了提供程序的性能 ...

  10. DOM对象控制HTML无素——详解1

    getElementsByName()方法 返回带有指定名称的节点对象的集合. 语法: document.getElementsByName(name) 与getElementById() 方法不同的 ...