题目链接: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.

题目大意:

给出n个长度为6的圆,问你是否存在两个圆是一样的

题解:

考虑到n的取值范围,直接比较果断的TLE
那么我们考虑先把每个数列hash,然后建立hash表,对于hash值相同的元素在当前的链表里暴力比较就好了
构造$hash(a_1,a_2...a_6)=\sum_{i=1}^{6}a_i+\prod_{i=1}^{6}a_i$
 
AC代码
#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表)的更多相关文章

  1. POJ 3349 Snowflake Snow Snowflakes(哈希表)

    题意:判断有没有两朵相同的雪花.每朵雪花有六瓣,比较花瓣长度的方法看是否是一样的,如果对应的arms有相同的长度说明是一样的.给出n朵,只要有两朵是一样的就输出有Twin snowflakes fou ...

  2. POJ 3349 Snowflake Snow Snowflakes (哈希表)

    题意:每片雪花有六瓣,给出n片雪花,六瓣花瓣的长度按顺时针或逆时针给出,判断其中有没有相同的雪花(六瓣花瓣的长度相同) 思路:如果直接遍历会超时,我试过.这里要用哈希表,哈希表的关键码key用六瓣花瓣 ...

  3. POJ 3349 Snowflake Snow Snowflakes (Hash)

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

  4. [ACM] POJ 3349 Snowflake Snow Snowflakes(哈希查找,链式解决冲突)

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

  5. 哈希—— POJ 3349 Snowflake Snow Snowflakes

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

  6. POJ 3349 Snowflake Snow Snowflakes(简单哈希)

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

  7. POJ 3349 Snowflake Snow Snowflakes

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

  8. poj 3349:Snowflake Snow Snowflakes(哈希查找,求和取余法+拉链法)

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

  9. hash应用以及vector的使用简介:POJ 3349 Snowflake Snow Snowflakes

    今天学的hash.说实话还没怎么搞懂,明天有时间把知识点总结写了,今天就小小的写个结题报告吧! 题意: 在n (n<100000)个雪花中判断是否存在两片完全相同的雪花,每片雪花有6个角,每个角 ...

随机推荐

  1. 0x16 Trie

    这章刷的真带劲 嘿嘿 裸题 #include<cstdio> #include<iostream> #include<cstring> #include<cs ...

  2. Jenkins+Docker部署Maven聚合工程

    这几天,把公司的预发布环境,改成docker部署,遇到了一些坑,有jenkins里的部署脚本的问题,也有harbor仓库的问题,还有docker远程访问的问题,还有DooD....一堆坑 Jenkin ...

  3. 完整注册+JQuery验证+selert后台校验

    Java代码 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8 ...

  4. Python笔记(四)

    # -*- coding:utf-8 -*- # 控制语句 # if...else... print "********************1********************** ...

  5. vue项目中遇到的打印,以及处理重新排版后不显示echarts图片问题。

    1. 项目中用到的打印 页面: css: 控制好宽度一般A4 我调试的是794px多了放不下,小了填不满.当时多页打印的时候,一定要控制好每一个页面内容显示的高度不要超过一个页面,当然根据自己项目来. ...

  6. windows 下安装 php-memcached 扩展

    通过 phpinfo()观察 3 个参数,即 php 版本, ts/nts, vc6/vc9 根据上步中的参数,到http://pecl.php.net/ 下载匹配的 memcache.dll 再次观 ...

  7. JavaScript DOM编程艺术(第2版)学习笔记2(4~6章应用实例)

    本书的第4章使用第3章学到的操作DOM的方法和属性写了一个展示图片的网页,并在第5,6章对代码进行了优化. 第一版,搭建网页的静态结构,包括一级标题<h1>,无序列表清单<ul> ...

  8. 初学C#,总结一下.sln和.csproj的区别

    1.sln:solusion 解决方案 csproj:c sharp project C#项目 csproj文件大家应该不会陌生,那就是C#项目文件的扩展名,它是“C Sharp Project”的缩 ...

  9. udev的规则文件

    转载于:https://linux.cn/article-9365-1.html 介绍 在 GNU/Linux 系统中,虽然设备的底层支持是在内核层面处理的,但是,它们相关的事件管理是在用户空间中通过 ...

  10. 测试用html

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...