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设计模式学习之九——命令模式

    一.命令模式使用场景及定义 命令模式常见的使用场景是:有时候需要向某些对象发送请求,但是并不知道请求的接受者是谁,也不知道请求的具体操作是什么.此时希望用一种松耦合的方式来设计程序,使得请求的发送者和 ...

  2. Hint

    select  /*+  first_rows(20)  */  *  from  t  where  id<20 --分页 select  /*+  all_rows  */  *  from ...

  3. ios-XML文档解析之SAX解析

    首先SAX解析xml *xml文档的格式特点是节点,大体思路是把每个最小的子节点作为对象的属性,每个最小子节点的'父'节点作为对象,将节点转化为对象,输出. 每个节点都是成对存在的,有开始有结束.有始 ...

  4. Leetcode: Insert Delete GetRandom O(1)

    Design a data structure that supports all following operations in average O(1) time. insert(val): In ...

  5. 免费VPN 实测可用

    vpngate.net 的镜像站点列表 (更新于 2014-05-18 03:06:00 UTC): http://121.135.220.121:26633/cn/ (Mirror location ...

  6. Android深入浅出之Binder机制

    一说明 Android系统最常见也是初学者最难搞明白的就是Binder了,很多很多的Service就是通过Binder机制来和客户端通讯交互的.所以搞明白Binder的话,在很大程度上就能理解程序运行 ...

  7. spark history-server的使用

    为什么需要historyServer? 在运行Spark Application的时候,Spark会提供一个WEBUI列出应用程序的运行时信息:但该WEBUI随着Application的完成(成功/失 ...

  8. 基于fullpage的幻灯片播放

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="utf-8&quo ...

  9. c 指针(一)

    一:什么是指针 变量i  的存储地址为P(假设为2000),*P  为指针变量 一个变量的地址称为该变量的“指针”.如果有另一个变量专门存放另一变量的地址(指针),则它称为“指针变量”. 指针是一个地 ...

  10. beta2阶段组员分数分配

    小组名称:nice! 小组成员:李权 于淼 刘芳芳 韩媛媛 宫丽君 项目内容:约跑app 分数分配规则 个人贡献分=项目基础分*0.5+个人代码贡献量*0.5 基本贡献分 个人代码贡献量 个人贡献分 ...