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

 
题目大意:给出n片雪花,没片雪花有六个角,每个角的长度均给出,问有没有两片相同的雪花,如果存在,就输出“Twin snowflakes found.”,如果不存在,就输出“No two snowflakes are alike.”
思路:这道题目用链表来做比较简单,所以用类似于邻接表的思想。哈希表存储的是六角边之和对max的余数,作为同类雪花(六角边之和对max的余数相同的数)的头结点。
代码:
 #include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define max 100010
struct vode
{
int f[];
struct vode *next;
};
struct vode *hash[];
int n,flag=;
void add(int f[],int sum)
{
sum=sum%max;
int i,j;
struct vode *p;
p=hash[sum];
while(p)
{
for(i=;i<=;i++)
if(f[i]==p->f[])
{
for(j=;j<=;j++)
if(f[(i+j)%]!=p->f[j])break;
if(j==)
{
flag=;
return ;
}
for(j=;j<=;j++)
if(f[((i-j)%+)%]!=p->f[j])break;
if(j==)
{
flag=;
return ;
}
}
p=p->next;
}
p=(struct vode *)malloc(sizeof(struct vode));
for(i=;i<=;i++)
p->f[i]=f[i];
p->next=hash[sum];
hash[sum]=p;
}
int main()
{
memset(hash,NULL,sizeof(hash));
scanf("%d",&n);
while(n--)
{
int i,f[],sum=;
for(i=;i<=;i++)
{
scanf("%d",&f[i]);
sum+=f[i];
}
if(flag)continue;
else add(f,sum);
}
if(flag)printf("Twin snowflakes found.");
else printf("No two snowflakes are alike.");
printf("\n");
return ;
}

Snowflake Snow Snowflakes(哈希表的应用)的更多相关文章

  1. poj3349 Snowflake Snow Snowflakes —— 哈希表

    题目链接:http://poj.org/problem?id=3349 题意:雪花有6个瓣,有n个雪花,输入每个雪花的瓣长,判断是否有一模一样的雪花(通过旋转或翻转最终一样,即瓣长对应相等).如果前面 ...

  2. POJ3349 Snowflake Snow Snowflakes(哈希)

    题目链接. 分析: 哈希竟然能这么用.检查两片雪花是否相同不难,但如果是直接暴力,定会超时.所以要求哈希值相同时再检查. AC代码: #include <iostream> #includ ...

  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: 30529   Accep ...

  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

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

  7. 哈希-Snowflake Snow Snowflakes 分类: POJ 哈希 2015-08-06 20:53 2人阅读 评论(0) 收藏

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

  8. POJ 3349:Snowflake Snow Snowflakes 六片雪花找相同的 哈希

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

  9. [poj3349]Snowflake Snow Snowflakes(hash)

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

随机推荐

  1. 项目:DoubleFaceCamera

    代码在github: https://github.com/Viyu/DoubleFacedCamera 这个app的想法是:用手机的前置和后置摄像头同时拍摄画面合成输出一张图,把拍摄者和被拍摄者的画 ...

  2. gcc编译时对'xxxx'未定义的引用问题

    gcc编译时对’xxxx’未定义的引用问题 gcc编译时对’xxxx’未定义的引用问题 原因 解决办法 gcc 依赖顺序问题 在使用gcc编译的时候有时候会碰到这样的问题,编译为.o(obj) 文件没 ...

  3. linux 编程环境搭建过程记录

    1, 安装centos 7 最小版  过程略 ...... 2, 安装桌面安装yum groupinstall "GNOME Desktop" 更新系统运行级别ln -sf /li ...

  4. JavaScript——Prototype详探

    用过JavaScript的同学们肯定都对prototype如雷贯耳,但是这究竟是个什么东西却让初学者莫衷一是,只知道函数都会有一个prototype属性,可以为其添加函数供实例访问,其它的就不清楚了, ...

  5. Game of Life I & II

    According to the Wikipedia's article: "The Game of Life, also known simply as Life, is a cellul ...

  6. Unity3D研究院之手游开发中所有特殊的文件夹(转)

    这里列举出手游开发中用到了所有特殊文件夹. 1.Editor Editor文件夹可以在根目录下,也可以在子目录里,只要名子叫Editor就可以.比如目录:/xxx/xxx/Editor  和 /Edi ...

  7. UVA 156 Ananagrams ---map

    题目链接 题意:输入一些单词,找出所有满足如下条件的单词:该单词不能通过字母重排,得到输入文本中的另外一个单词.在判断是否满足条件时,字母不分大小写,但在输出时应保留输入中的大小写,按字典序进行排列( ...

  8. 自定义Button 的图片设置不显示问题。

    如果你是自定义button  那么你设置图片就要用 button.imageView.image = [UIImage imageName:@""]; 如果你是给系统原生的butt ...

  9. mysql无法启动

    当在安装mysql服务时,有时会遇到恶心的PID错误而导致安装后无法启动以下为针对mysql-5.5版本在安装mysql时所遇到的问题的解决方法. 1.可能是/usr/local/mysql/data ...

  10. jquery 建议编辑器

    用谷歌搜索找了很久,发现所有的插件都是功能太复杂,不是我想要的.所以,我决定我自己来实现需要的编辑功能.刚开始我觉得应该要花费很多的时间,因为我想象内容编辑功能应该是很复杂的. 但事实证明,它是如此简 ...