题目描述
English Tiếng Việt 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 agged by your program as possibly identical.

输入格式

  • The first line of input will contain a single integer n; 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 snowflake. 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.

输出格式
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 snowflakes, your program should print the message:

Twin snowflakes found.

题意翻译
题目描述
你可能听说过,没有两片雪花是相同的。你要写一个程序,判断这是不是真的。你的程序会读到一些有关于这些雪花的信息,找到一对完全相同的雪花。每片雪花有六个角。对于每个雪花,你的程序会获得每个角的长度。我们认为两片雪花相同,当且仅当它们各自从某一个角开始,逆时针或顺时针记录长度,能得到两个相同的六元组。

输入输出格式
输入格式:
-第一行只有一个数字n,代表雪花的数量。

-接下来会有n行,每一行描述了一片雪花。每片雪花会按逆时针或顺时针给出六个角的长度a1,a2…a6。我们认为两片雪花相同,当且仅当它们各自从某一个角开始,逆时针或顺时针记录长度,能得到两个相同的六元组。例如,同一片雪花可以被描述为1 2 3 4 5 6 或 4 3 2 1 6 5。

输出格式
如果没有两片雪花是相同的,请输出 :
“No two snowflakes are alike. ”

否则,请输出:

“Twin snowflakes found.”

#include<cstdio>
#include<cstring>
const int SZ = 1e5+7, MOD = 99991;
int tot, snow[SZ][6], head[SZ], tail[SZ], next[SZ];
bool equal(int a[], int b[]) {for(int i = 1; i < 6; ++i)for(int j = 0, k; j < 6; j++) {for(k = 0; k < 6; ++k)if(a[(i+k)%6] != b[(j+k)%6])break;if(k == 6) return true;for(k = 0; k < 6; k++)if(a[(i+k)%6] != b[(j+6-k)%6])break;if(k == 6) return true;}return false;
}
int Hash(int a[]) {int sum = 0, mul = 1;for(int i = 0; i < 6; i++) {sum = (sum + a[i]) % MOD;mul = 1LL * mul * a[i] % MOD;}return (sum + mul) % MOD;
}
bool insert(int a[]) {int val = Hash(a);for(int i = head[val]; i ; i = next[i])if(equal(snow[i], a)) return true;++tot;//Äڴ濽±´£¬°ÑÊý×éaµÄÄÚÈÝ¿½±´µ½snow[tot]ÖÐ //Ä¿±êµØÖ· ÆðʼµØÖ· ¿½±´³¤¶È memcpy(snow[tot], a, 6*sizeof (int));next[tot] = head[val], head[val] = tot;return false;
}
int main() {int n, a[6];scanf("%d", &n);for(int i = 0; i < n; i++) {for(int j = 0; j < 6; j++)scanf("%d", a+j);if(insert(a)) {puts("Twin snowflakes found.");return 0;}}puts("No two snowflakes are alike.");return 0;
}

TWINSNOW - Snowflakes 哈希相关推荐

  1. POJ3349 Snowflake Snow Snowflakes(哈希表)

    题目链接http://poj.org/problem?id=3349 题意是说,有n片雪花,每片雪花都是有6个角,给出每片雪花每个角的长度,问里面有没有一样的雪花(给出数据的顺序是没有确定的). 虽然 ...

  2. 题解 [SP4354][AcWing137]TWINSNOW - Snowflakes/雪花雪花雪花

    Luogu link 洛谷的翻译不太清楚,这里是acwing题目链接:https://www.acwing.com/problem/content/139/ 题解 算法:hash+邻接表+(最小表示法 ...

  3. SP4354 TWINSNOW - Snowflakes

    难度:5 知识点:散列 这个题一开始犯了一个低级错误,就是没有输入n,找了好久,然后就是主要思路,首先就是散列函数的设计,这个我参考的进阶指南上面的,用和与乘积的和作为散列的下标,然后就是对于两个雪花 ...

  4. 【POJ3349】Snowflake Snow Snowflakes(哈希表判重,维护一个集合)

    problem 有n片雪花,每片有6个脚,每个脚有一个长度. 两片雪花是一样的当且仅当每个脚的长度顺序都一样(顺逆时针和开始位置不管) 求n片雪花中是否有一样的雪花. solution 维护一个哈希表 ...

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

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

  6. ***POJ 3349 Snowflake Snow Snowflakes(哈希)

    第一次学习哈希,基本模仿题解写的 思路:首先这题时间比较紧,所以只能用加法求余来构造哈希表,然后容易出现冲突,所以冲突之后还需要判断是否为同种. 并且雪花有顺逆时针,所以需要两种时针方向,每种时针方向 ...

  7. 基本数据结构—Hash哈希

    理论概念 这玩意一直都是个好东西,但是我总觉得玄学的一批.今天借着专题学习的劲头,把Hash好好梳理一下. 定义/作用 哈希这东西应该都不陌生.将复杂的信息映射到一个容易维护的值域之内.那么Hash函 ...

  8. POJ 3349 Snowflake Snow Snowflakes

    /* 哈希第一题啊..! 谢谢 http://www.cnblogs.com/Dario67/archive/2011/04/09/2010724.html 的博主 这题投机取巧了,判断是否相等 直接 ...

  9. POJ3349 哈希算法

    问题分析 在n (n<100000)个雪花中判断是否存在两片完全相同的雪花,每片雪花有6个角,每个角的长度限制为1000000 雪花相等的条件为, 雪花6个角的长度按顺序相等(这个顺序即可以是顺 ...

最新文章

  1. Objective-c的@property 详解
  2. ASP.net 2.0 自定义控件的开发之数据分页 第二章
  3. matlab智能算法30个案例分析_赞!继电保护25个事故案例分析总结,值得收藏!...
  4. 打印菱形(曼哈顿距离法)
  5. CString + UINT Error:有多个运算符+=与这些操作数匹配
  6. window命令查看cpu核数_win7如何查内存条型号机CPU 信息【通过命令来查看】
  7. ValueError: too many values to unpack
  8. php v9开发网站,phpcms开发步骤
  9. 智能运维究竟能为DBA带来什么?听听4位专家怎么说
  10. SQL Server数据库是否会引发恶意?
  11. 站立会议03--个人总结
  12. 设置元素浮动的几种方式
  13. java nio 追加写文件_java.nio.file读写文件
  14. break 退出循环
  15. assert函数_类成员函数指针在成员函数内部的调用
  16. java messagedigest_JAVA MessageDigest(MD5加密等)
  17. 雷石服务器不显示加密狗,ESXi服务器不识别USB加密狗怎么办
  18. 如何破解校园网wifi?怎样破解校园网不能共享wifi?校园网路由器如何破解?
  19. matlab交流电路仿真,单相交流调压电路Matlab仿真
  20. 《A Survey on Evolutionary Computation for Complex Continuous Optimization》笔记

热门文章

  1. 【UML】UML建模
  2. 找玩具 概率 dfs
  3. 2022年6月大学英语六级翻译
  4. 特征图谱字典_空间数据图谱为特征
  5. 罗技k380键盘-数字键上的字符对不上怎么办?
  6. 用计算机打有一群人去喝酒的游戏,适合聚会时玩的40个小游戏
  7. 企业群发短信时为什么要找短信平台公司而不是直接找运营商发送
  8. 需账号密码登陆的网页爬虫
  9. 我对于外包开发的看法
  10. Logisitc Regression 预测员工离职率