http://poj.org/problem?id=3349

Snowflake Snow Snowflakes
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)的更多相关文章

  1. POJ 3349 Snowflake Snow Snowflakes (Hash)

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

  2. 哈希—— POJ 3349 Snowflake Snow Snowflakes

    相应POJ题目:点击打开链接 Snowflake Snow Snowflakes Time Limit: 4000MS   Memory Limit: 65536K Total Submissions ...

  3. POJ 3349 Snowflake Snow Snowflakes(简单哈希)

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

  4. POJ 3349 Snowflake Snow Snowflakes

    Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 27598 Accepted: ...

  5. [ACM] POJ 3349 Snowflake Snow Snowflakes(哈希查找,链式解决冲突)

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

  6. poj 3349:Snowflake Snow Snowflakes(哈希查找,求和取余法+拉链法)

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

  7. hash应用以及vector的使用简介:POJ 3349 Snowflake Snow Snowflakes

    今天学的hash.说实话还没怎么搞懂,明天有时间把知识点总结写了,今天就小小的写个结题报告吧! 题意: 在n (n<100000)个雪花中判断是否存在两片完全相同的雪花,每片雪花有6个角,每个角 ...

  8. [poj 3349] Snowflake Snow Snowflakes 解题报告 (hash表)

    题目链接:http://poj.org/problem?id=3349 Description You may have heard that no two snowflakes are alike. ...

  9. POJ 3349 Snowflake Snow Snowflakes Hash

    题目链接: http://poj.org/problem?id=3349 #include <stdio.h> #include <string.h> #include < ...

  10. POJ 3349 Snowflake Snow Snowflakes(哈希)

    http://poj.org/problem?id=3349 题意 :分别给你n片雪花的六个角的长度,让你比较一下这n个雪花有没有相同的. 思路:一开始以为把每一个雪花的六个角的长度sort一下,然后 ...

随机推荐

  1. javascript:void(0)和javascript:;的用法

    一.JavaScript:void(0) 我们经常会使用到 javascript:void(0) 这样的代码,那么在 JavaScript 中 javascript:void(0) 代表的是什么意思呢 ...

  2. 框架基础——全面解析Java注解

    为什么学习注解? 学习注解有什么好处? 学完能做什么? 答:1. 能够读懂别人写的代码,特别是框架相关的代码: 2. 让编程更加简洁,代码更加清晰: 3. 让别人高看一眼. spring.mybati ...

  3. ASCII码表和转义字符

    Bin Dec Hex 缩写/字符 解释 0000 0000 0 0 NUL(null) 空字符 0000 0001 1 1 SOH(start of headline) 标题开始 0000 0010 ...

  4. 运行sql server profiler所需的权限

    ********运行Sql Server Profiler所需的权限(performance)*********/ --EG. -- 使用TRACE帐户(Performancetest)跟踪Sql S ...

  5. stack note

    参考 http://www.cnblogs.com/java06/archive/2012/10/16/3122428.html 1,顺序栈 定义栈: #define stacksize 1000; ...

  6. 当AS3遇见Swift(一)

    当AS3遇见Swift 从Hello开始 As3 trace(“Hello Eko”) Swift println(“Hello Eko”) 挺象,有点隔壁王叔叔的意思. 常量和变量 As3 publ ...

  7. G面经prepare: Android Phone Unlock Pattern

    1 2 3 4 5 6 7 8 9 只有中间没有其他键的两个键才能相连,比如1可以连 2 4 5 6 8 但不能连 3 7 9 但是如果中间键被使用了,那就可以连,比如5已经被使用了,那1就可以连9 ...

  8. 我与 美国作家 21天精通C++ 作者 Rao的对话:

    这就是动力呀!

  9. [原创]spring学习笔记:关于springsource-tool-suite插件的安装

    1.首先我们得确定自己使用的eclipes的版本,具体方式:打开eclipes > help > About Eclipes > 点击eclipes的logo > 查看ecli ...

  10. c++之路进阶——codevs1286(郁闷的出纳员)

    1286 郁闷的出纳员 2004年NOI全国竞赛  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 大师 Master       题目描述 Description OIER公司 ...