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. 第三篇 Replication:事务复制-发布服务器

    本篇文章是SQL Server Replication系列的第三篇,详细内容请参考原文. 发布服务器是所有复制数据的源头.每一个发布服务器上可以定义多个发布.每一个发布包含一组项目(项目在同一个数据库 ...

  2. WHERE谓词对索引使用的影响

    本篇博文只测试WHERE谓词对multi-column index使用的影响,主要篇幅是SQL代码+截图.详细内容请参考<Inside the SQL Server Query Optimize ...

  3. Vue.2.0.5-深入响应式原理

    大部分的基础内容我们已经讲到了,现在讲点底层内容.Vue 最显著的一个功能是响应系统 -- 模型只是普通对象,修改它则更新视图.这会让状态管理变得非常简单且直观,不过理解它的原理以避免一些常见的陷阱也 ...

  4. 异常处理原则--good

    异常机制是现代主流语言的标配,但是异常处理问题虽然已经被讨论很多,也有很多经典书籍的论述,却一直都充满争议.很多人都觉得异常处理很难拿捏,同时也难以理解一些语言或库的异常处理设计.我使用Java近10 ...

  5. mysql:innodb monitor(show engine innodb status)探秘

    在旧的版本里面是show innodb status命令,新版本后改动了一些:show engine innodb status; 我们最熟悉的,应当就是show innodb status命令,可以 ...

  6. tableview在第一次显示时会自动relodata

    tableview在第一次显示时会自动加载数据

  7. HUD 5086 Revenge of Segment Tree(递推)

    http://acm.hdu.edu.cn/showproblem.php?pid=5086 题目大意: 给定一个序列,求这个序列的子序列的和,再求所有子序列总和,这些子序列是连续的.去题目给的第二组 ...

  8. [原创]java WEB学习笔记89:Hibernate学习之路-- -Hibernate检索方式(5种),HQL介绍,实现功能,实现步骤,

    本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...

  9. gson使用注意事项

    public static Object toBean(String jsonString, Class<?> beanclass) { GsonBuilder gsonb = new G ...

  10. shell学习笔记(1)-变量

    1.shell中的变量可以自定义,shell中使用变量时用$ name="shero"echo "hi ${name}" root@shero-virtual- ...