3088:Snowflake

总时间限制:

30000ms

单个测试点时间限制:

1000ms

内存限制:

65536kB

描述

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.

输入

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.

输出

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.

样例输入

2
1 2 3 4 5 6
4 3 2 1 6 5

样例输出

Twin snowflakes found.
将每个六元组hash起来实现O(1)查找
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
using namespace std;
const int Prime=99991;
int n;
int a[100005][6];
vector<int>Hash[Prime];
bool Identical(int x,int y)
{for(int i=0;i<6;++i){if(a[x][i]==a[y][0]&&a[x][(i+1)%6]==a[y][1]&&a[x][(i+2)%6]==a[y][2]&&a[x][(i+3)%6]==a[y][3]&&a[x][(i+4)%6]==a[y][4]&&a[x][(i+5)%6]==a[y][5]){return true;} if(a[x][i]==a[y][0]&&a[x][(i+5)%6]==a[y][1]&&a[x][(i+4)%6]==a[y][2]&&a[x][(i+3)%6]==a[y][3]&&a[x][(i+2)%6]==a[y][4]&&a[x][(i+1)%6]==a[y][5]){return true;} } return false;
}
int main()
{cin>>n;for(int i=0;i<n;++i){for(int j=0;j<6;++j){cin>>a[i][j];}}for(int i=0;i<n;++i){int sum=0;for(int j=0;j<6;++j){sum+=a[i][j];}sum=sum%Prime;for(int j=0;j<Hash[sum].size();++j){if(Identical(i,Hash[sum][j])){cout<<"Twin snowflakes found."<<endl;return 0;}}Hash[sum].push_back(i);}cout<<"No two snowflakes are alike."<<endl;return 0;
}

poj3088:Snowflake (Hash)相关推荐

  1. 东超科技于上市公司有关系_科技公司可以从有史以来最大的软件上市中学到什么...

    东超科技于上市公司有关系 Despite sharing a name with the slang term to imply that someone is "soft and frag ...

  2. UVa 3349 Snowflake Snow Snowflakes(Hash)

    http://poj.org/problem?id=3349 题意: 给出n片雪花留个角的长度,要求判断是否有一样的雪花. 思路: Hash表的应用. 首先将每个雪花所有角的总长计算出来,如果两片雪花 ...

  3. POJ3349 Snowflake Snow Snowflakes(hash)

    题意: 雪花有六条棱,每条棱对应一个数,要求在一组雪花中看能否寻找到所有棱对应相同的雪花(棱有顺序要求). 要点: 刚自学了一下hash,这题刚上手有点思路但自己实在也写不出来,看了网上的代码觉得还是 ...

  4. Snowflake Snow Snowflakes(Hash + 链式前向星)

    一.题意 每片雪花是由6个角组成,每片雪花的6个角由顺时针的顺序给出,当两片雪花顺时针或逆时针的角度相同时,则为雪花是同一片雪花.问n片雪花中是否有相同的雪花. 二.题解 我们定义HashHashHa ...

  5. POJ 3349 Snowflake Snow Snowflakes hash

    题意:每个雪花有六个角,每个角用一个数字表示.输入n个雪花,若存在两个雪花相等则输出Twin snowflakes found.否则输出No two snowflakes are alike. 题解: ...

  6. Snowflake Snow Snowflakes(hash)

    F - Snowflake Snow Snowflakes Time Limit:4000MS     Memory Limit:65536KB     64bit IO Format:%I64d & ...

  7. snowflake mysql_snowflake数据库

    一.数据库瓶颈 不管是IO瓶颈,还是CPU瓶颈,最终都会导致数据库的活跃连接数增加,进而逼近甚至达到数据库可承载活跃连接数的阈值.在业务Service来看就是,可用数据库连接少甚至无连接可用.接下来就 ...

  8. 基本数据结构—Hash哈希

    理论概念 这玩意一直都是个好东西,但是我总觉得玄学的一批.今天借着专题学习的劲头,把Hash好好梳理一下. 定义/作用 哈希这东西应该都不陌生.将复杂的信息映射到一个容易维护的值域之内.那么Hash函 ...

  9. 诸多老牌数据仓库厂商当前,Snowflake如何创近12年最大IPO金额

    摘要:在数据仓库/分析领域,有传统厂商Oracle,Teradata,开源软件Hadoop,云厂商AWS Redshift,Google Bigquery,Snowflake成功的技术原因是什么? 1 ...

最新文章

  1. linux 内核调试前准备(简单记录,以后补充)
  2. 基于 HTTP 协议的 3 种实时数据获取技术
  3. 《图书管理系统——java》
  4. 分别写出引入CSS的3种方式, 特点, 优先级
  5. 解析linux中的vfs文件系统机制,解析Linux中的VFS文件系统机制
  6. 原反补移码的概念应用以及异或的作用
  7. 七牛HTML 上传按钮,七牛 JSSDK 配置+常见问题
  8. Apache的目录结构详细讲解
  9. Pwn-2018_HITB_CTF-gundam
  10. [noip模拟赛]算算数
  11. 171221—8421BCD码、进制转换
  12. 工作流系统之四十二 业务规则和业务过程
  13. 顽童时代-----钟丽思
  14. 交换游戏 (记忆化搜索 状压)
  15. mkdir: Failed on local exception: java.io.IOException: javax.security.sasl.SaslException: GSS initia
  16. 三维GIS可视化技术在智慧城市基本建设中的作用
  17. 大学物理实验长度的测量实验报告_大学物理实验:长度测量
  18. Oracle创建多个(大量)属性表,建表语句如下,案例是创建509个属性的表
  19. 佛山市大学生落户政策2023年入户条件介绍
  20. Android动态壁纸解析

热门文章

  1. 标题DSP 数字信号处理:线性卷积、循环卷积、圆周卷积计算
  2. 单词2016.8.3
  3. 电容触摸屏测试软件,一种电容式触摸屏的测试方法、系统及电子设备专利_专利查询 - 天眼查...
  4. 徐国定 教授 计算机,编译原理|精品课程|华东师范大学
  5. MSP430F5529与LCD1602显示模块(上)
  6. web基础学习(六)CSS3 文字阴影、文本溢出、服务器字体
  7. 黑马JAVA P138 Map集合案例、其他实现类
  8. C#实现的 写字板 程序
  9. 怎样用计算机算屋面的坡度,坡度怎么算( 屋面找坡,应该如何计算)
  10. 社交媒体分析:洞察希拉里面对的性别歧视