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. Eclipse打开当前所属文件所在windows中的文件夹

    1.Eclipse设置 依次展开如下菜单:    Run ---- External Tools ---- External Tools Configurations    在 program 下面新 ...

  2. 兼容IE浏览器的placeholder【超不错】

    jQuery EnPlaceholder plug (兼容IE浏览器的placeholder)使用 >>>>>>>>>>>>&g ...

  3. int? 参数是这个的时候 是可以传入null的 而int的就不行

    such as     pager.CurrentPageIndex = (page != null ? (int)page : 1);

  4. 那些年,我们一起学WCF--(8)Single实例行为

    Single实例行为,类似于单件设计模式,所有可以客户端共享一个服务实例,这个服务实例是一个全局变量,该实例第一次被调用的时候初始化,到服务器关闭的时候停止. 设置服务为Single实例行为,只要设置 ...

  5. 使用charles proxy for Mac来抓取手机App的网络包

    之前做Web项目的时候,经常会使用Fiddler(Windows下).Charles Proxy(Mac下)来抓包,调试一些东西:现在搞Android App开发,有时候也需要分析手机App的网络请求 ...

  6. JavaScript HTML DOM - 改变CSS

    JavaScript HTML DOM - 改变CSS HTML DOM 允许 JavaScript 改变 HTML 元素的样式. 改变 HTML 样式 如需改变 HTML 元素的样式,请使用这个语法 ...

  7. SGU 223.Little Kings

    时间限制:0.25s 空间限制:4M 题意: 在 n*n(n≤10)的棋盘上放 k (k<=n*n)个国王(可攻击相邻的 8 个格子),求使它们无法互相攻击的方案数. Solution: 采用状 ...

  8. Struts2中的链接标签 <s:url>和<s:a>---在action中获取jsp表单提交的参数(转)

    转自:http://sgl124764903.iteye.com/blog/444183 1.普通链接 Web程序中最普通的应用是链接到其他页面,下面看Welcome.jsp. <%@ page ...

  9. Extjs 4学习2

    主要学习采自:http://www.ishowshao.com/blog/2012/06/19/extjs-4-getting-started/ 用的sdk为extjs4.2.1 根据其中的提示装了一 ...

  10. 在Lufylegend中如何设置bitmap或者sprite的缩放和旋转中心

    最近两天有个lufylegend游戏引擎群的群友需要做一个项目,其中要解决的需求是:获取照相机拍摄的图片,根据图片的EXIF信息让图片显示为“正常”情况,并且需要给图片添加一些事件侦听.何为正常呢?就 ...