Snowflake Snow Snowflakes
Time Limit: 4000MS   Memory Limit: 65536K
Total Submissions: 35642   Accepted: 9373

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.

题意是有很多片雪花,每一个雪花有六片,问这些雪花中是否有相同的雪花,注意雪花可以旋转,即可以循环向前移动或是向后移动,变成相等的情况。

两两比对会TLE,哈希做,六个值的和mod一个质数 作为key,然后有 和相等 的情况下,逐一比对是否含有完全相等的情况。

代码:

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#pragma warning(disable:4996)
using namespace std; const int N1 = 15000;
const int N2 = 100;
int num,m[15000]; struct no {
int sno[7];
}node[N1][N2]; bool check(no node_one,int pos, int x)
{
int i, j;
bool flag = false;
for (j = 0; j < 6; j++)
{
for (i = 1; i <= 6; i++)
{
if (node_one.sno[i] != node[pos][x].sno[(i + j) % 6 + 1])
{
break;
}
if (i == 6)
{
return true;
}
}
} for (j = 7; j >= 2 ; j--)
{
for (i = 1; i <= 6; i++)
{
if (node_one.sno[i] != node[pos][x].sno[(j-i+6)%6+1])
{
break;
}
if (i == 6)
return true;
}
}
return flag;
} int main()
{ int i,j,pos;
bool flag = true;
no node_one; memset(m, 0, sizeof(m));
scanf("%d", &num); for (i = 1; i <= num; i++)
{
for (j = 1; j <= 6; j++)
{
scanf("%d",&node_one.sno[j]);
}
pos = (node_one.sno[1] + node_one.sno[2] + node_one.sno[3] + node_one.sno[4] + node_one.sno[5] + node_one.sno[6])%14997; for (j = 0; j < m[pos]; j++)
{
if (check(node_one,pos,j))
{
puts("Twin snowflakes found.");
return 0;
}
}
node[pos][m[pos]] = node_one;
m[pos]++;
}
puts("No two snowflakes are alike.");
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

POJ 3349:Snowflake Snow Snowflakes 六片雪花找相同的 哈希的更多相关文章

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

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

  2. 哈希—— POJ 3349 Snowflake Snow Snowflakes

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

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

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

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

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

  5. POJ 3349 Snowflake Snow Snowflakes (Hash)

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

  6. POJ 3349 Snowflake Snow Snowflakes

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

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

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

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

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

  9. POJ - 3349 Snowflake Snow Snowflakes (哈希)

    题意:给定n(0 < n ≤ 100000)个雪花,每个雪花有6个花瓣(花瓣具有一定的长度),问是否存在两个相同的雪花.若两个雪花以某个花瓣为起点顺时针或逆时针各花瓣长度依次相同,则认为两花瓣相 ...

随机推荐

  1. Python 之并发编程之线程下

    七.线程局部变量 多线程之间使用threading.local 对象用来存储数据,而其他线程不可见 实现多线程之间的数据隔离 本质上就是不同的线程使用这个对象时,为其创建一个只属于当前线程的字典 拿空 ...

  2. Java自学-集合框架 ArrayList和HashSet的区别

    Java ArrayList和HashSet的区别 示例 1 : 是否有顺序 ArrayList: 有顺序 HashSet: 无顺序 HashSet的具体顺序,既不是按照插入顺序,也不是按照hashc ...

  3. win8.1 virtualbox 安装centos7注意事项

    win8.1是64位的,一开始在virtualbox中选择版本时,怎么也选不到64位的,这时要改BIOS设置,把CPU虚拟化改为允许. virtualbox是32位的,没必要非得是64位(64位的也不 ...

  4. mapreduce课上测试

    今天上课的时候进行了一个mapreduce的实验,但是由于课下对于mapreduce还有hive的理解不够透彻,因此导致了课上没能完成这次实验. 关于本次课堂上的实验的内容大致为: 1.对一个70k的 ...

  5. elk安装2.0版本,自己总结,比较细致 es单机的安装

    用root用户会报错,版本6之前还是可以用root用户启动的,针对es的保护,数据的一些问题,6之后就不允许了. 启动成功 下面验证一下  可以直接用浏览器访问,接受http访问 配置,因为没有暴露端 ...

  6. tf.reduce_max 与 reduce 系列 API

    reduce 可以理解为 python 里的 reduce 函数: tensorflow 中有很多 reduce_ API,其用法完全相同 tf.reduce_max 以这个为例进行说明 def re ...

  7. 笔记-Python-性能优化

    笔记-Python-性能优化 1.      开始 1.1.    python性能差么? 做一个判断前,先问是不是. python运行效率低是事实. 1.2.    为什么? 原因: Python是 ...

  8. MessageBox函数

    <Windows程序设计>(第五版)(美Charles Petzold著) https://docs.microsoft.com/zh-cn/windows/desktop/apiinde ...

  9. 时间和日期实例-<Calender计算出生日期相差几天>

    String day1="1994:10:04"; String day2="1994:10:03"; SimpleDateFormat format= new ...

  10. IDEA启动项目的时候,控制台中显示的都是乱码

    解决办法: 找到intellij idea安装目录,bin文件夹下面idea64.exe.vmoptions和idea.exe.vmoptions这两个文件,分别在这两个文件中添加:-Dfile.en ...