POJ 3349:Snowflake Snow Snowflakes(数的Hash)
http://poj.org/problem?id=3349
Time Limit: 4000MS | Memory Limit: 65536K | |
Total Submissions: 37609 | Accepted: 9878 |
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.
#include<cstdio>
#include<algorithm>
#include <cstring>
#include <iostream>
using namespace std;
#define MOD 14997
struct node
{
int len[];
}snow,f[][];
int Hash[]; /*
第一道Hash
判断两个雪花是否相同:
分别是顺时针旋转和逆时针旋转,只要有一次是满足条件的就可以当成是一样的
一开始MOD取了999983,结果MLE了,后来看了一下别人的才取了14997
*/
bool check(node a,node b)
{
int i,j,k;
bool flag;
//顺时针旋转判断
for(i=;i<;i++){
flag=true;
for(j=i,k=;k<;k++,j=(j+)%){
if(a.len[j]!=b.len[k]){
flag=false;break;
}
}
if(flag) return ;
}
//逆时针旋转判断
for(i=;i<;i++){
flag=true;
for(j=i,k=;k<;k++,j=(j+)%){
if(a.len[j]!=b.len[k]){
flag=false;break;
}
}
if(flag) return ;
}
return ;
} int main()
{
int n;
int now;
scanf("%d",&n);
//只有一组样例就不初始化了
bool flag=false;
for(int i=;i<n;i++){
now=;
for(int j=;j<;j++){
scanf("%d",&snow.len[j]);
now+=snow.len[j]%MOD;
}
if(flag) continue;
now%=MOD;
if(Hash[now]>){
for(int j=;j<=Hash[now];j++){
if(check(snow,f[now][j])){
flag=true;break;
}
}
}
Hash[now]++;
f[now][Hash[now]]=snow;
}
if(flag) printf("Twin snowflakes found.\n");
else printf("No two snowflakes are alike.\n");
return ;
}
2016-06-04
POJ 3349:Snowflake Snow Snowflakes(数的Hash)的更多相关文章
- POJ 3349 Snowflake Snow Snowflakes (Hash)
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 48646 Accep ...
- 哈希—— POJ 3349 Snowflake Snow Snowflakes
相应POJ题目:点击打开链接 Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions ...
- POJ 3349 Snowflake Snow Snowflakes(简单哈希)
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 39324 Accep ...
- POJ 3349 Snowflake Snow Snowflakes
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 27598 Accepted: ...
- [ACM] POJ 3349 Snowflake Snow Snowflakes(哈希查找,链式解决冲突)
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 30512 Accep ...
- poj 3349:Snowflake Snow Snowflakes(哈希查找,求和取余法+拉链法)
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 30529 Accep ...
- hash应用以及vector的使用简介:POJ 3349 Snowflake Snow Snowflakes
今天学的hash.说实话还没怎么搞懂,明天有时间把知识点总结写了,今天就小小的写个结题报告吧! 题意: 在n (n<100000)个雪花中判断是否存在两片完全相同的雪花,每片雪花有6个角,每个角 ...
- [poj 3349] Snowflake Snow Snowflakes 解题报告 (hash表)
题目链接:http://poj.org/problem?id=3349 Description You may have heard that no two snowflakes are alike. ...
- POJ 3349 Snowflake Snow Snowflakes Hash
题目链接: http://poj.org/problem?id=3349 #include <stdio.h> #include <string.h> #include < ...
- POJ 3349 Snowflake Snow Snowflakes(哈希)
http://poj.org/problem?id=3349 题意 :分别给你n片雪花的六个角的长度,让你比较一下这n个雪花有没有相同的. 思路:一开始以为把每一个雪花的六个角的长度sort一下,然后 ...
随机推荐
- 分享书籍[writing idiomatic python ebook] 二
对多个变量设置相同的值时,用连等号一起赋值 x = 10 y = 10 z = 10 改成: x = y = z = 10 交换变量值时,可以避免定义新的临时变量 x = 10 y = 5 temp ...
- ios数字转emoj表情
+(NSString *)convertSimpleUnicodeStr:(NSString *)inputStr{ ,); UTF32Char inputChar = ; // unicodeInt ...
- javascript实例学习之三——类新浪微博的登录框
该登录框和百度的搜索框类似,可以实现如下效果: 1.文字输入时自动弹出提示层 2,提示层根据输入文字进行自动过滤 3,提示层可以使用上下按键进行选择 4,提示层可以点击或者回车来确认输入 微博登录框h ...
- runtime获取类名,遍历变量,遍历对象,遍历方法
- ATS连接 https
HTTPS协议是Http Over SSL,简单来说就是HTTP的安全版本,在HTTP的基础上增加SSL/TLS加密传输协议,通过HTTPS加密传输和身份认证保证了传输过程的安全性.在登录网银和电子邮 ...
- python+selenium实现跨浏览器兼容性测试
python https://www.python.org/ python是一种脚本语言, 易学易用,可以助你快速实现业务逻辑,高效集成系统. ----- http://zh.wikipedia.or ...
- mongodb远程连接以及备份、还原、导出、导入
一.远程连接mongodb 连接命令:mongo -u username -p pwd 192.168.41.215:27017/database(用户名对应的数据库) 二.mongodump备份数据 ...
- networkcommon v3开源消息框架资料
http://www.cnblogs.com/csdev/category/870400.html
- 《30天自制操作系统》07_day_学习笔记
harib04a: P126 获取按键编码: 让程序在按下键盘的键之后,将键值编码显示出来 修改的是前面编写的鼠标按键的处理键盘中断的函数inthandler21() 这里笔者介绍了怎样把中断号 ...
- 创建纯洁的TableViewCell
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPat ...