判断n朵雪花中,是否有完全一样的雪花。简单的hash,将雪花的六个边的权值加起来,记为sum,将sum相等的雪花归为一类,再在这里面根据题意找完全相同的,判断顺时针或者逆时针的所有角是否一模一样。

#include<vector>
#include<stdio.h>
int MOD=;
std::vector<int> snow[];
int arm[][];
int isSame(int s1,int s2){
for(int i=;i<;i++){
int flag=;
for(int j=,k=i;j<;j++,k=(k+)%){
if(arm[s1][j]!=arm[s2][k]){
flag=;
break;
}
}
if(flag) return ;
}
for(int i=;i<;i++){
int flag=;
for(int j=,k=i;j>=;j--,k=(k+)%){
if(arm[s1][j]!=arm[s2][k]){
flag=;
break;
}
}
if(flag) return ;
}
return ;
}
int main() {
int N;
scanf("%d",&N);
int flag=;
for(int i=;i<N;i++){
int sum=;
for(int j=;j<;j++){
scanf("%d",&arm[i][j]);
sum+=arm[i][j];
}
if(flag)
continue;
sum=sum%MOD;
for(int j=;j<snow[sum].size();j++){
flag=isSame(snow[sum][j],i);
if(flag)
break;
}
snow[sum].push_back(i);
}
if(flag)
printf("Twin snowflakes found.\n");
else
printf("No two snowflakes are alike.\n");
return ;
}

附:

 
Time Limit: 4000MS   Memory Limit: 65536K
Total Submissions: 34732   Accepted: 9119

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.

Snowflake Snow Snowflakes - poj 3349 (hash函数)的更多相关文章

  1. Snowflake Snow Snowflakes POJ - 3349 Hash

    题意:一个雪花有六个角  给出N个雪花 判断有没有相同的(可以随意旋转) 参考:https://blog.csdn.net/alongela/article/details/8245005 注意:参考 ...

  2. 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 wh ...

  3. POJ--3349 Snowflake Snow Snowflakes(数字hash)

    链接:Snowflake Snow Snowflakes 判断所有的雪花里面有没有相同的 每次把雪花每个角的值进行相加和相乘 之后hash #include<iostream> #incl ...

  4. 【POJ3349 Snowflake Snow Snowflakes】【Hash表】

    最近在对照省选知识点自己的技能树 今天是Hash 题面 大概是给定有n个6元序列 定义两个序列相等 当两个序列各自从某一个元素开始顺时针或者逆时针旋转排列能得到两个相同的序列 求这n个6元序列中是否有 ...

  5. POJ 3349:Snowflake Snow Snowflakes(数的Hash)

    http://poj.org/problem?id=3349 Snowflake Snow Snowflakes Time Limit: 4000MS   Memory Limit: 65536K T ...

  6. POJ 3349 Snowflake Snow Snowflakes (Hash)

    Snowflake Snow Snowflakes Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 48646   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

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

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

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

随机推荐

  1. 解密所有APP运行过程中的内部逻辑(转)

    转贴地址:http://www.freebuf.com/tools/54562.html 0×01前言 这年头,apk 全都是加密啊,加壳啊,反调试啊,小伙伴们表示已经不能愉快的玩耍了.静态分析越来越 ...

  2. Flex State

    在Flex 程序中,引入了状态设计的概念.在一个程序中,按照功能的需求,将界面切分成相对独立的部分.运行过程中,随着用户交互,界面在各个部分之间切换.比如在购物车程序中,登录界面.选购商品界面.购物车 ...

  3. 2017年最全的30个Android面试题,你将如何回答?

    百度首页 登录 2017年最全的30个Android面试题,你将如何回答? 机翼技术 百家号 03-10 02:32 “三金四银”又是一年一度的跳槽季,相信有不少Android程序员开始摩拳擦掌蠢蠢欲 ...

  4. 8、面向对象class

    对象的概念同其他语言的对象相同 一个基本的类 #!/usr/bin/python class person: def hi(self,name): print 'Hello,%s'%name p1= ...

  5. ubuntu16.04新服务器上配置selenium+firefox

    ubuntu16.041安装pythonsudo apt-get install python默认2.7.122更新apt-getsudo apt-get update更新下apt-get库否则下载p ...

  6. solr 统计频率(term frequency)

    1.统计单词在某个字段出现的频率次数 term frequency实现使用了function query. 例如统计‘公司’这个关键字在text这个字段中出现的次数 在返回的时候进行计算统计,即在返回 ...

  7. Gitlab备份、迁移、恢复和升级

    Gitlab备份.迁移.恢复和升级 自建的Gitlab服务器常常会因为使用时间的增长,其空间容量等硬件需求都需要升级,或者迁移至更高配置的服务器上.备份.迁移.恢复.升级过程如下 1.gitlab备份 ...

  8. javascript http库axios

    还是那个开源项目中的代码看到的: 直接看axios官方的介绍吧,里面的用法介绍很全: https://github.com/mzabriskie/axios Installing Using npm: ...

  9. [Flutter] Creating & Updating State in a Flutter Application

    To create a Stateful widget: 1. Create a StatefulWidget 2. Create a State class SGreeting extends St ...

  10. Nehe OpenGL lesson 8

    lesson8 Blending: http://nehe.gamedev.net/tutorial/lessons_06__10/17010/ (也许须要特殊手段訪问) There was a re ...