[poj 3349] Snowflake Snow Snowflakes 解题报告 (hash表)
题目链接: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.
题目大意:
题解:
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<iostream> const int N=1e5+;
const int P=1e5+;
int n,tot;
int head[N],snow[N][],next[N];
int H(int *a)
{
int sum=,re=;
for (int i=;i<;i++)
{
sum=(sum+a[i])%P;
re=1ll*re*a[i]%P;
}
return (sum+re)%P;
}
bool equal(int *a,int *b)
{
for (int i=;i<;i++)
for (int j=;j<;j++)
{
bool flag=true;
for (int k=;k<;k++) if (a[(i+k)%]!=b[(j+k)%]) flag=false;
if (flag) return true;
flag=true;
for (int k=;k<;k++) if (a[(i+k)%]!=b[(j-k+)%]) flag=false;
if (flag) return true;
}
return false;
}
bool insert(int *a)
{
int val=H(a);
for (int i=head[val];i;i=next[i])
{
if (equal(snow[i],a)) return true;
}
++tot;
for (int i=;i<;i++) snow[tot][i]=a[i];
next[tot]=head[val];
head[val]=tot;
return false;
}
int main()
{
int a[];
scanf("%d",&n);
for (int i=;i<=n;i++)
{
for (int j=;j<;j++) scanf("%d",a+j);
if (insert(a))
{
puts("Twin snowflakes found.");
return ;
}
}
puts("No two snowflakes are alike.");
return ;
}
[poj 3349] Snowflake Snow Snowflakes 解题报告 (hash表)的更多相关文章
- POJ 3349 Snowflake Snow Snowflakes(哈希表)
题意:判断有没有两朵相同的雪花.每朵雪花有六瓣,比较花瓣长度的方法看是否是一样的,如果对应的arms有相同的长度说明是一样的.给出n朵,只要有两朵是一样的就输出有Twin snowflakes fou ...
- POJ 3349 Snowflake Snow Snowflakes (哈希表)
题意:每片雪花有六瓣,给出n片雪花,六瓣花瓣的长度按顺时针或逆时针给出,判断其中有没有相同的雪花(六瓣花瓣的长度相同) 思路:如果直接遍历会超时,我试过.这里要用哈希表,哈希表的关键码key用六瓣花瓣 ...
- POJ 3349 Snowflake Snow Snowflakes (Hash)
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 48646 Accep ...
- [ACM] POJ 3349 Snowflake Snow Snowflakes(哈希查找,链式解决冲突)
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 30512 Accep ...
- 哈希—— POJ 3349 Snowflake Snow Snowflakes
相应POJ题目:点击打开链接 Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions ...
- POJ 3349 Snowflake Snow Snowflakes(简单哈希)
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 39324 Accep ...
- POJ 3349 Snowflake Snow Snowflakes
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 27598 Accepted: ...
- poj 3349:Snowflake Snow Snowflakes(哈希查找,求和取余法+拉链法)
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 30529 Accep ...
- hash应用以及vector的使用简介:POJ 3349 Snowflake Snow Snowflakes
今天学的hash.说实话还没怎么搞懂,明天有时间把知识点总结写了,今天就小小的写个结题报告吧! 题意: 在n (n<100000)个雪花中判断是否存在两片完全相同的雪花,每片雪花有6个角,每个角 ...
随机推荐
- v-cli环境的安装
第一步:node npm是node的包管理器 yarn 第二步:npm install -g vue-cli或者淘宝镜像 如果安装失败:在node.js com ...
- Asp.net Web Api中使用配置Unity
第一步:建立web api,添加unity.webapi. 第二步:在添加了该引用之后,在App_Start中会自动生成UnityConfig.cs文件 第三步:添加数据做测试 第四步:展示效果
- for循环的写法及优化
最近这几天在研究浏览器性能的时候发现了一些小知识,在此做一总结: 其中经常用到的for循环有:正常的for循环,for in循环,for of循环等,但是对于正常的for循环可以做一下优化,使得其在执 ...
- 解决 Windows XP 下 IIS 最大连接数为 10 的问题
为了方便调试网站程序,就在 Windows XP 系统下安装了 IIS,但是出现了一个问题:“403.9 误-禁止访问:连接的用户过多”,会有这样的问题出现,一般有两种可能:一.IIS 本身的最大连接 ...
- 小学生都能学会的python(闭包和迭代器)
小学生都能学会的python(闭包和迭代器) 1. 函数名第一类对象 函数名其实就是变量名 1). 可以像变量一样互相赋值. 2). 可以作为函数的参数,进行传递 3). 可以作为返回值返回 4). ...
- CSS3特效——六面体
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- web.xml中Filter过滤器标签说明
原文:http://www.cnblogs.com/edwardlauxh/archive/2010/03/11/1918618.html 在研究liferay框架中看到Web.xml中加入了过滤器的 ...
- open函数详解
转载:https://www.cnblogs.com/frank-yxs/p/5925574.html open函数用来在进程中打开文件,如果成功则返回一个文件描述符fd. ============= ...
- 2015 Multi-University Training Contest 3 hdu 5318 The Goddess Of The Moon
The Goddess Of The Moon Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/ ...
- java Timer定时器管理类
1.java timer类,定时器类.启动执行定时任务方法是timer.schedule(new RemindTask(), seconds*1000);俩参数分别是TimerTask子类,具体执行定 ...