Snowflake Snow Snowflakes POJ - 3349(hash)
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. 题意:给n朵雪花,每个雪花都有6条边,找出是否有两个相同的雪花。
思路:n²遍历肯定不行,然后就想到hash,对于存放hash值的邻接表,我用的是vector,事实证明很慢啊,手写前向星快很多。
hash:我用的是直接相加然后取模一个素数的方法,当然还有很多其他方法,各种异或或者骚运算应该都差不多。 (对于equl函数,我错了很久,之前写的是用while找到一个pos位置和b【0】相同,就退出,然后我发现,找到一个不够,也许有下一个不能直接退出)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std; const int SIZE = ;
int n,tot,p=;
int snow[SIZE][];
vector<int>v[SIZE]; int h(int a)
{
int sum=;
for(int i=;i<;i++)
{
sum = (sum + snow[a][i]) % p;
}
return sum % p;
}; bool equl(int a,int b)
{
for(int j=;j<;j++)
{
if(snow[a][j] != snow[b][])continue;
int flag = ;
for(int i=; i<; i++)
{
if(snow[a][(j + i)%] != snow[b][i] )
flag = ;
}
if(flag)
return ;
flag = ;
for(int i=; i<; i++)
{
if(snow[a][(j-i+)%] != snow[b][i])
flag = ;
}
if(flag) return ;
}
return ;
} bool Insert(int a)
{
int val = h(a);
int len = v[val].size();
for(int i=;i<len;i++)
{ if(equl(v[val][i],a))return ;
}
v[val].push_back(a);
return ;
} int main()
{
scanf("%d",&n);
int flag = ;
for(int i=;i<=n;i++)
{
for(int j=;j<;j++)
{
scanf("%d",&snow[i][j]);
}
if(!flag && Insert(i))
{
puts("Twin snowflakes found.");
flag = ;
}
}
if(!flag)
puts("No two snowflakes are alike.");
}
Snowflake Snow Snowflakes POJ - 3349(hash)的更多相关文章
- [poj 3349] Snowflake Snow Snowflakes 解题报告 (hash表)
题目链接:http://poj.org/problem?id=3349 Description You may have heard that no two snowflakes are alike. ...
- Snowflake Snow Snowflakes POJ - 3349 Hash
题意:一个雪花有六个角 给出N个雪花 判断有没有相同的(可以随意旋转) 参考:https://blog.csdn.net/alongela/article/details/8245005 注意:参考 ...
- Snowflake Snow Snowflakes - poj 3349 (hash函数)
判断n朵雪花中,是否有完全一样的雪花.简单的hash,将雪花的六个边的权值加起来,记为sum,将sum相等的雪花归为一类,再在这里面根据题意找完全相同的,判断顺时针或者逆时针的所有角是否一模一样. # ...
- POJ 3349:Snowflake Snow Snowflakes(数的Hash)
http://poj.org/problem?id=3349 Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K T ...
- POJ 3349 Snowflake Snow Snowflakes (Hash)
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 48646 Accep ...
- POJ 3349 Snowflake Snow Snowflakes(简单哈希)
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 39324 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(哈希查找,求和取余法+拉链法)
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 30529 Accep ...
- POJ--3349 Snowflake Snow Snowflakes(数字hash)
链接:Snowflake Snow Snowflakes 判断所有的雪花里面有没有相同的 每次把雪花每个角的值进行相加和相乘 之后hash #include<iostream> #incl ...
随机推荐
- Ftp上传的方法
using System;using System.Collections.Generic;using System.IO;using System.Net;using System.Text; na ...
- git的学习笔记(一):git本地操作
1.Git介绍 Git是一个开源的分布式版本控制软件,用以有效.高速的处理从很小到非常大的项目版本管理. Git 最初是由Linus Torvalds设计开发的,用于管理Linux内核开发. Git ...
- 'mysql' 不是内部或外部命令,也不是可运行的程序或批处理文件
今天安装完MYSQL8.0的版本,根据课本的提示,在CMD里运行,出现了'mysql' 不是内部或外部命令,也不是可运行的程序或批处理文件.在网上搜了一下,他的解决方法是这样的: 1.设置一下环境变量 ...
- Confluence 6 配置服务器基础地址
服务器基础地址(Server Base URL)是用户访问 Confluence 的 URL 地址.这个基础的 URL 地址必须与你在浏览器中访问 Confluence 中的地址. Confluenc ...
- Confluence 6 数据库表-内容(Content)
这部分的内容描述了有关 Confluence 存储内容所使用的表格.内容是用户在 Confluence 存储和分享的信息. attachmentdata 附件文件的二进制数据.当 Confluence ...
- Confluence 6 修改站点的标识图片
你可以通过修改标识图片(Logos)来修改你 Confluence 站点的外观和感觉. 你可以修改: 站点标识图片(site logo) 为所有空间修改默认空间标识图片(default space l ...
- 移动端touchstart,touchmove,touchend
近段时间使用html5开发一个公司内部应用,而触摸事件必然是移动应用中所必须的,刚开始以为移动设备上或许也会支持鼠标事件,原来是不支持的,好在webkit内核的移动浏览器支持touch事件,并且打包成 ...
- 树形dp 入门
今天学了树形dp,发现树形dp就是入门难一些,于是好心的我便立志要发一篇树形dp入门的博客了. 树形dp的概念什么的,相信大家都已经明白,这里就不再多说.直接上例题. 一.常规树形DP P1352 没 ...
- 初始Ajax
一.Ajax准备知识:json 说起json,我们大家都了解,就是python中的json模块,那么json模块具体是什么呢?那我们现在详细的来说明一下 1.json(Javascript Obie ...
- SpringBoot图片上传(一)
简单描述:点击上传文件的图标,上传文件,上传成功后,图标编程上传的图片. 吐槽:文件上传下载这种东西,总是感觉莫名的虚-_-|| 也不知道是造了什么孽,(其实就是IO File这一块的知识了解的不太 ...