Snowflake Snow Snowflakes
Time Limit: 4000MS   Memory Limit: 65536K
Total Submissions: 27312   Accepted: 7213

题目链接:http://poj.org/problem?id=3349

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.

Source

CCC 2007
题目大意:给出n片雪花,没片雪花有六个角,每个角的长度均给出,问有没有两片相同的雪花,如果存在,就输出“Twin snowflakes found.”,如果不存在,就输出“No two snowflakes are alike.”
思路:这道题目用链表来做比较简单,所以用类似于邻接表的思想。哈希表存储的是六角边之和对max的余数,作为同类雪花(六角边之和对max的余数相同的数)的头结点。
代码:

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<stdlib.h>
 4 #define max 100010
 5 struct vode
 6 {
 7     int f[6];
 8     struct vode *next;
 9 };
10 struct vode *hash[1000010];
11 int n,flag=0;
12 void add(int f[],int sum)
13 {
14     sum=sum%max;
15     int i,j;
16     struct vode *p;
17     p=hash[sum];
18     while(p)
19     {
20         for(i=0;i<=5;i++)
21         if(f[i]==p->f[0])
22         {
23             for(j=1;j<=5;j++)
24             if(f[(i+j)%6]!=p->f[j])break;
25             if(j==6)
26             {
27                 flag=1;
28                 return ;
29             }
30             for(j=1;j<=5;j++)
31             if(f[((i-j)%6+6)%6]!=p->f[j])break;
32             if(j==6)
33             {
34                 flag=1;
35                 return ;
36             }
37         }
38         p=p->next;
39     }
40     p=(struct vode *)malloc(sizeof(struct vode));
41     for(i=0;i<=5;i++)
42     p->f[i]=f[i];
43     p->next=hash[sum];
44     hash[sum]=p;
45 }
46 int main()
47 {
48     memset(hash,NULL,sizeof(hash));
49     scanf("%d",&n);
50     while(n--)
51     {
52         int i,f[6],sum=0;
53         for(i=0;i<=5;i++)
54         {
55             scanf("%d",&f[i]);
56             sum+=f[i];
57         }
58         if(flag)continue;
59         else add(f,sum);
60     }
61     if(flag)printf("Twin snowflakes found.");
62     else printf("No two snowflakes are alike.");
63     printf("\n");
64     return 0;
65 }

View Code

转载于:https://www.cnblogs.com/kuangdaoyizhimei/p/3268962.html

Snowflake Snow Snowflakes(哈希表的应用)相关推荐

  1. POJ3349 Snowflake Snow Snowflakes(哈希表)

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

  2. 【POJ No. 3349】 雪花 Snowflake Snow Snowflakes

    [POJ No. 3349] 雪花 Snowflake Snow Snowflakes POJ 题目地址 [题意] 你可能听说过没有两片雪花是一样的,请编写一个程序来确定这是否是真的. 已知每片雪花6 ...

  3. Snowflake Snow Snowflakes

    文章目录 Snowflake Snow Snowflakes Snowflake Snow Snowflakes 题意: 给定一个n个六边形雪花,判定是否存在相同的 分析: 链表hash hash 值 ...

  4. Snowflake Snow Snowflakes(hash)

    F - Snowflake Snow Snowflakes Time Limit:4000MS     Memory Limit:65536KB     64bit IO Format:%I64d & ...

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

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

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

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

  7. POJ 3349 Snowflake Snow Snowflakes

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

  8. UVa 3349 Snowflake Snow Snowflakes(Hash)

    http://poj.org/problem?id=3349 题意: 给出n片雪花留个角的长度,要求判断是否有一样的雪花. 思路: Hash表的应用. 首先将每个雪花所有角的总长计算出来,如果两片雪花 ...

  9. POJ3349 Snowflake Snow Snowflakes(hash)

    题意: 雪花有六条棱,每条棱对应一个数,要求在一组雪花中看能否寻找到所有棱对应相同的雪花(棱有顺序要求). 要点: 刚自学了一下hash,这题刚上手有点思路但自己实在也写不出来,看了网上的代码觉得还是 ...

最新文章

  1. 华南理工大学计算机应用基础随堂作业,华南理工大学计算机应用基础随堂练习题目及答案...
  2. .htaccess伪静态实例记录
  3. php分开每个字,PHP,分解每个句子之间有特殊字符的文本文件
  4. java 门面模式_Java门面模式
  5. java私有方法单元测试_如何通过java反射的方式对java私有方法进行单元测试
  6. android安全攻防实践_网络攻防小组招新,等待优秀的你!
  7. java socket编程 聊天_基于java的socket简单聊天编程
  8. Flink_大数据技术之电商用户行为分析
  9. 【codevs1220】数字三角形
  10. 3.数据结构 --- 栈和队列
  11. 抢小米软件html版(简单有效)
  12. 智能车制作——速度环PID
  13. 【论文解读】VDN( Variational Denoising Network )变分去噪网络
  14. FME安装版本的选择
  15. 基于Bootstrap模板创建门户网站vue项目02
  16. Python数据的输出
  17. opencv第九天pro
  18. zzuli1728(数学期望,组合数)
  19. ajax传递数组怎么传?ajax数组传递
  20. mysql的password()函数和md5函数

热门文章

  1. PDPS软件:机器人抓手工具运动机构制作与仿真运行测试
  2. excel在每行下面添加插入指定行数的空白行方法步骤
  3. UML软件建模StarUML
  4. 检测域名微信屏蔽,检测微信域名屏蔽API
  5. LVS负载均衡群集合集
  6. SAP S4 会计科目表的设计
  7. 如何查看主板型号 教你怎么看主板型号
  8. npm installCould not resolve dependency:peer... 原因和解决方案
  9. 成功体验Katalon框架测试安卓APK(一)
  10. ImportError: No module named datetime全局python解决time显示问题