判断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. Vim复制一整行和复制多行

    1.复制 1)单行复制 在命令模式下,将光标移动到将要复制的行处,按“yy”进行复制: 2)多行复制 在命令模式下,将光标移动到将要复制的首行处,按“nyy”复制n行:其中n为1.2.3…… 2.粘贴 ...

  2. iptables配置

    iptables -F iptables -P INPUT DROP iptables -P FORWARD DROP iptables -A INPUT -m state --state ESTAB ...

  3. 为Linux上FireFox安装Flash插件

    废话少说,步骤如下: 1.点击网页上插件缺失处,根据提示下载tar.gz版本的插件,我下载的版本是install_flash_player_11_linux.i386.tar.gz,这个文件被下载到了 ...

  4. docker入门——管理容器

    除了交互式的容器(interactive container),我们也可以创建长期运行的容器.守护式容器(daemonized container)没有交互式会话,非常适合运行应用程序和服务.大多数时 ...

  5. Centos系统信息及日志

    1.确认内核版本: #uname -r #uname -a 2.确认发行版本: #cat /etc/redhat-release 3.查看系统载入的模块: #lsmod | grep XXX 载入一个 ...

  6. Cookie小案例-----记住浏览过的商品记录

    Cookie小案例------记住浏览过的商品记录 我们知道,这个功能在电商项目中非经常见.这里处理请求和页面显示都是由servlet实现,主要是为了体现cookie的作用, 实现功能例如以下: 1, ...

  7. 【Android进阶】怎样使用文件来保存程序中的数据

    在程序中.有非常多保存和获取数据的方法,本篇文章,主要介绍使用文件系统对程序中的数据进行保存和读取的操作 我直接写了一个帮助类,进行文件的写入和读取操作 /** * 用于在文件里保存程序数据 * * ...

  8. Tomcat几种启动报错及解决办法

    今天真跪了,tomcat的错想到想不到的都遇到了.不记录一下都愧对今天愁掉的hair 在此之前分享一个集错网站,应该是程序员必备的网站之一,不过纯英文,小酸爽 Tags - Stack Overflo ...

  9. Oracle创建DataBase Links

    -- Drop existing database link drop database link GJA_CFMDM_LINK;-- Create database link create data ...

  10. iframe元素获取

    应用场景:main.jsp 中有Iframe,其中包含 home.jsp,在main.jsp中的dom元素绑定的方法操作home.jsp中元素.或反之操作.