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. nginx+nginx-rtmp-module+ffmpeg搭建流媒体服务器[转]

    转 :http://redstarofsleep.iteye.com/blog/2123752 Nginx本身是一个非常出色的HTTP服务器,FFMPEG是非常好的音视频解决方案.这两个东西通过一个n ...

  2. HDU 1503 带回朔路径的最长公共子串

    http://acm.hdu.edu.cn/showproblem.php?pid=1503 这道题又WA了好几次 在裸最长公共子串基础上加了回溯功能,就是给三种状态各做一个 不同的标记.dp[n][ ...

  3. PHP5.4开启zend opcache缓存

    PHP5.5整合了zend opcache,但是5.4以下的需要自己安装. 介绍一下开启opcache方法,环境为wamp(php5.4.16) 下载dll文件 把php_opcache.dll放进p ...

  4. Java 重写(Overriding)和重载(Overloading)

    方法的重写(Overriding)和重载(Overloading)是java多态性的不同表现. 重写是父类与子类之间多态性的一种表现 重载是一类中多态性的一种表现.

  5. ZJOIDay2T1 BB题解

    讲道理我是调不出来了... 考虑对序列按下标维护每个节点最后的树. 那么 改操作点 - 把一段连续的节点改父亲 加点/删点(注意拆成两个操作了) 插儿子 那么用seg维护一下下标, 用ETT维护Dep ...

  6. Java文件读写操作指定编码方式防乱码

    读文件:BufferedReader 从字符输入流中读取文本,缓冲各个字符,从而提供字符.数组和行的高效读取. 可以指定缓冲区的大小,或者可使用默认的大小.大多数情况下,默认值就足够大了. 通常,Re ...

  7. poj 1572

    一道字符串替换的题目. 题意:给你2*n组字符串,一个是规则,一个是替换的结果. 字符串的题目,确实麻烦,有些细节不处理好就是wa. 这里我提供1组数据 intput 1 abcdef a abcde ...

  8. zju3430

    题意:给出多个加密的模式串,和多个待匹配的串,问每个串里出现了多少种模式串.加密方法是把每3bytes加密成按6bits一个对应成4个字符,对应方法题里给了. 分析:除了解密之外,基本是个赤裸裸的AC ...

  9. C# 静态函数调用窗体控件

    回调函数方法是静态函数,需要调用窗体控件,赋值或取值. 定义 public static Form1 mainFrm;   mainFrm = this; public partial class F ...

  10. selenium 右键下载图片,结合sikuli

    上一次写右键下载是结合robot,这次是使用selenium+sikuli 上一次日志:http://www.cnblogs.com/tobecrazy/p/3969390.html 有关sikuli ...